2023-09-18 15:41:41 +03:30
|
|
|
|
namespace Brizco.Repository.Handlers.Task;
|
2023-09-18 09:45:02 +03:30
|
|
|
|
|
|
|
|
|
|
public class CreateActivityCommandHandler : IRequestHandler<CreateTaskCommand, TaskLDto>
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IRepositoryWrapper _repositoryWrapper;
|
2023-09-18 15:41:41 +03:30
|
|
|
|
private readonly ICurrentUserService _currentUserService;
|
|
|
|
|
|
|
|
|
|
|
|
public CreateActivityCommandHandler(IRepositoryWrapper repositoryWrapper,ICurrentUserService currentUserService)
|
2023-09-18 09:45:02 +03:30
|
|
|
|
{
|
|
|
|
|
|
_repositoryWrapper = repositoryWrapper;
|
2023-09-18 15:41:41 +03:30
|
|
|
|
_currentUserService = currentUserService;
|
2023-09-18 09:45:02 +03:30
|
|
|
|
}
|
|
|
|
|
|
public async Task<TaskLDto> Handle(CreateTaskCommand request, CancellationToken cancellationToken)
|
|
|
|
|
|
{
|
2023-09-18 15:41:41 +03:30
|
|
|
|
if (_currentUserService.ComplexId == null)
|
|
|
|
|
|
throw new AppException("ComplexId is null", ApiResultStatusCode.NotFound);
|
|
|
|
|
|
if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId))
|
|
|
|
|
|
throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound);
|
2023-09-18 09:45:02 +03:30
|
|
|
|
var task = Domain.Entities.Task.Task
|
|
|
|
|
|
.Create(request.Title,
|
|
|
|
|
|
request.Description,
|
|
|
|
|
|
request.Type,
|
|
|
|
|
|
request.IsDisposable,
|
|
|
|
|
|
request.SetFor,
|
|
|
|
|
|
request.HasDisposed,
|
|
|
|
|
|
request.Amount,
|
2023-09-18 15:41:41 +03:30
|
|
|
|
request.AmountType,
|
|
|
|
|
|
complexId);
|
2023-09-18 09:45:02 +03:30
|
|
|
|
|
|
|
|
|
|
|
2023-11-13 14:42:49 +03:30
|
|
|
|
|
|
|
|
|
|
if (request.Shifts.Count == 0)
|
|
|
|
|
|
throw new AppException("اگر فعالیت برای یک گروه نقش انتخاب شده باشد باید لیست نقش ها را ارسال نمایید");
|
|
|
|
|
|
task.AddShift(request.Shifts.ToArray());
|
|
|
|
|
|
|
|
|
|
|
|
if (request.Positions.Count == 0)
|
|
|
|
|
|
throw new AppException("اگر فعالیت برای یک گروه نقش انتخاب شده باشد باید لیست نقش ها را ارسال نمایید");
|
|
|
|
|
|
task.AddShift(request.Positions.ToArray());
|
2023-09-18 09:45:02 +03:30
|
|
|
|
|
|
|
|
|
|
_repositoryWrapper.SetRepository<Domain.Entities.Task.Task>().Add(task);
|
|
|
|
|
|
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
|
|
|
|
return task.AdaptToLDto();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|