diff --git a/DigitalData.UserManager.Application/Key.cs b/DigitalData.UserManager.Application/Key.cs index 38c6090..eec4b67 100644 --- a/DigitalData.UserManager.Application/Key.cs +++ b/DigitalData.UserManager.Application/Key.cs @@ -8,5 +8,7 @@ public static readonly string UserAlreadyExists = "UserAlreadyExists"; public static readonly string UserNotFound = "UserNotFound"; public static readonly string UnauthorizedUser = "UnauthorizedUser"; + public static readonly string DateRangeNotXNOR = "DateRangeNotXNOR"; + public static readonly string InvalidDateRange = "InvalidDateRange"; } -} +} \ No newline at end of file diff --git a/DigitalData.UserManager.Application/Services/UserRepService.cs b/DigitalData.UserManager.Application/Services/UserRepService.cs index 2e946ce..348b7c9 100644 --- a/DigitalData.UserManager.Application/Services/UserRepService.cs +++ b/DigitalData.UserManager.Application/Services/UserRepService.cs @@ -5,13 +5,16 @@ using DigitalData.UserManager.Application.DTOs.UserRep; using DigitalData.UserManager.Domain.Entities; using DigitalData.UserManager.Infrastructure.Contracts; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Logging; namespace DigitalData.UserManager.Application.Services { public class UserRepService : BaseService, IUserRepService { + private readonly IStringLocalizer _localizer; public UserRepService(IUserRepRepository repository, IStringLocalizer localizer, IMapper mapper) : base(repository, mapper) { + _localizer = localizer; } public async Task>> ReadAllAsync(bool withUser = false, bool withRepGroup = false, bool withGroup = false, bool withRepUser = false, int? userId = null, int? groupId = null) @@ -20,5 +23,15 @@ namespace DigitalData.UserManager.Application.Services var urReadDTOs = _mapper.Map>(urs); return Result.Success(urReadDTOs); } + + public override async Task> CreateAsync(UserRepCreateDto createDto) + // XOR control + => (createDto.ValidFrom is null && createDto.ValidTo is not null) || (createDto.ValidFrom is not null && createDto.ValidTo is null) + ? Result.Fail().Notice(LogLevel.None, Flag.DataIntegrityIssue, _localizer[Key.DateRangeNotXNOR]) + //date range control + : (createDto.ValidFrom > createDto.ValidTo) + ? Result.Fail().Notice(LogLevel.None, Flag.DataIntegrityIssue, _localizer[Key.InvalidDateRange]) + : await base.CreateAsync(createDto); + } } \ No newline at end of file