ref: project structure
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using mws.backend.dotnet.application.Common;
|
||||
using mws.backend.dotnet.domain.MasterData;
|
||||
|
||||
namespace mws.backend.dotnet.application.MasterData;
|
||||
|
||||
internal static class MasterDataValidation
|
||||
{
|
||||
public static async Task<MasterDataEntry> ValidateAsync(IUnitOfWork uow, SaveMasterDataRequest request, Guid? excludeId, CancellationToken ct)
|
||||
{
|
||||
var group = request.Group.Trim();
|
||||
var label = request.Label.Trim();
|
||||
var value = request.Value.Trim();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(group) || string.IsNullOrWhiteSpace(label) || string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
throw new BadRequestException("Group, label and value are required");
|
||||
}
|
||||
|
||||
if (await uow.MasterData.ExistsAsync(group, value, excludeId, ct))
|
||||
{
|
||||
throw new BadRequestException("An entry with this group and value already exists");
|
||||
}
|
||||
|
||||
return new MasterDataEntry
|
||||
{
|
||||
Group = group,
|
||||
Label = label,
|
||||
Value = value,
|
||||
SortOrder = request.SortOrder,
|
||||
IsActive = request.IsActive,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user