2024-07-08 17:45:17 +03:30
|
|
|
|
namespace Brizco.Repository.Handlers.Tasks;
|
2023-09-18 09:45:02 +03:30
|
|
|
|
|
2024-08-09 21:42:04 +03:30
|
|
|
|
public class CreateActivityCommandHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService)
|
|
|
|
|
|
: IRequestHandler<CreateTaskCommand, TaskLDto>
|
2023-09-18 09:45:02 +03:30
|
|
|
|
{
|
|
|
|
|
|
public async Task<TaskLDto> Handle(CreateTaskCommand request, CancellationToken cancellationToken)
|
|
|
|
|
|
{
|
2024-08-09 21:42:04 +03:30
|
|
|
|
if (currentUserService.ComplexId == null)
|
2023-09-18 15:41:41 +03:30
|
|
|
|
throw new AppException("ComplexId is null", ApiResultStatusCode.NotFound);
|
2024-08-09 21:42:04 +03:30
|
|
|
|
if (!Guid.TryParse(currentUserService.ComplexId, out Guid complexId))
|
2023-09-18 15:41:41 +03:30
|
|
|
|
throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound);
|
2024-07-06 21:20:10 +03:30
|
|
|
|
var task = Domain.Entities.Tasks.Task
|
2023-09-18 09:45:02 +03:30
|
|
|
|
.Create(request.Title,
|
|
|
|
|
|
request.Description,
|
|
|
|
|
|
request.Type,
|
|
|
|
|
|
request.IsDisposable,
|
2023-11-18 22:23:23 +03:30
|
|
|
|
DateTimeExtensions.UnixTimeStampToDateTime(request.SetFor),
|
2023-09-18 09:45:02 +03:30
|
|
|
|
request.HasDisposed,
|
|
|
|
|
|
request.Amount,
|
2023-09-18 15:41:41 +03:30
|
|
|
|
request.AmountType,
|
2023-11-18 22:23:23 +03:30
|
|
|
|
complexId,
|
|
|
|
|
|
request.ScheduleType);
|
2023-09-18 09:45:02 +03:30
|
|
|
|
|
2023-11-18 22:23:23 +03:30
|
|
|
|
if (request.Routines.Count == 0)
|
|
|
|
|
|
throw new AppException("لطفا روتین های وظیفه را انتخاب نمایید");
|
|
|
|
|
|
task.AddRoutine(request.Routines.ToArray());
|
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("اگر فعالیت برای یک گروه نقش انتخاب شده باشد باید لیست نقش ها را ارسال نمایید");
|
2023-11-18 22:23:23 +03:30
|
|
|
|
task.AddPosition(request.Positions.ToArray());
|
|
|
|
|
|
|
|
|
|
|
|
if (task.ScheduleType == TaskScheduleType.Weekly && request.Days.Count == 0)
|
|
|
|
|
|
throw new AppException("اگر تکرار فعالیت به صورت هفتگی باشد باید روزهای ان هفته را انتخاب کنید");
|
|
|
|
|
|
request.Days.ForEach(d=>task.SetDay(d));
|
|
|
|
|
|
|
2023-09-18 09:45:02 +03:30
|
|
|
|
|
2024-08-09 21:42:04 +03:30
|
|
|
|
repositoryWrapper.SetRepository<Domain.Entities.Tasks.Task>().Add(task);
|
|
|
|
|
|
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
2023-09-18 09:45:02 +03:30
|
|
|
|
return task.AdaptToLDto();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|