feat(UserRepService): Die Methode CreateAsync wurde überschrieben.
- XOR-Logik hinzugefügt, um zu prüfen, ob ValidFrom und ValidTo Null sind - Logik hinzugefügt, um zu kontrollieren, dass ValidFrom kleiner als ValidTo ist
This commit is contained in:
parent
c060cd9083
commit
a946ba871d
@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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<IUserRepRepository, UserRepCreateDto, UserRepReadDto, UserRepUpdateDto, UserRep>, IUserRepService
|
||||
{
|
||||
private readonly IStringLocalizer<Resource> _localizer;
|
||||
public UserRepService(IUserRepRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper) : base(repository, mapper)
|
||||
{
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public async Task<DataResult<IEnumerable<UserRepReadDto>>> 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<IEnumerable<UserRepReadDto>>(urs);
|
||||
return Result.Success(urReadDTOs);
|
||||
}
|
||||
|
||||
public override async Task<DataResult<int>> 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<int>().Notice(LogLevel.None, Flag.DataIntegrityIssue, _localizer[Key.DateRangeNotXNOR])
|
||||
//date range control
|
||||
: (createDto.ValidFrom > createDto.ValidTo)
|
||||
? Result.Fail<int>().Notice(LogLevel.None, Flag.DataIntegrityIssue, _localizer[Key.InvalidDateRange])
|
||||
: await base.CreateAsync(createDto);
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user