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 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, }; } }