2023-09-15 12:37:02 +03:30
|
|
|
|
namespace Brizco.Repository.Handlers.Shift;
|
|
|
|
|
|
|
2023-09-18 09:45:02 +03:30
|
|
|
|
public class CreateShiftCommandHandler : IRequestHandler<CreateShiftCommand, Domain.Entities.Shift.Shift>
|
2023-09-15 12:37:02 +03:30
|
|
|
|
{
|
|
|
|
|
|
private readonly IRepositoryWrapper _repositoryWrapper;
|
|
|
|
|
|
public CreateShiftCommandHandler(IRepositoryWrapper repositoryWrapper)
|
|
|
|
|
|
{
|
|
|
|
|
|
_repositoryWrapper = repositoryWrapper;
|
|
|
|
|
|
}
|
|
|
|
|
|
public async Task<Domain.Entities.Shift.Shift> Handle(CreateShiftCommand request, CancellationToken cancellationToken)
|
|
|
|
|
|
{
|
|
|
|
|
|
var shift = Domain.Entities.Shift.Shift
|
|
|
|
|
|
.Create(request.Title,
|
|
|
|
|
|
request.Description,
|
|
|
|
|
|
request.StartAt,
|
|
|
|
|
|
request.EndAt);
|
|
|
|
|
|
|
2023-09-18 09:45:02 +03:30
|
|
|
|
request.DayOfWeeks.ForEach(d => shift.SetDay(d));
|
2023-09-15 12:37:02 +03:30
|
|
|
|
|
|
|
|
|
|
_repositoryWrapper.SetRepository<Domain.Entities.Shift.Shift>().Add(shift);
|
|
|
|
|
|
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
|
|
|
|
return shift;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|