2024-07-08 17:45:17 +03:30
|
|
|
|
namespace Brizco.Repository.Handlers.Activities;
|
2023-09-18 09:45:02 +03:30
|
|
|
|
|
2024-08-09 21:42:04 +03:30
|
|
|
|
public class CreateActivityCommandHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService)
|
|
|
|
|
|
: IRequestHandler<CreateActivityCommand, ActivityLDto>
|
2023-09-18 09:45:02 +03:30
|
|
|
|
{
|
|
|
|
|
|
public async Task<ActivityLDto> Handle(CreateActivityCommand 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);
|
2023-09-20 11:54:12 +03:30
|
|
|
|
try
|
|
|
|
|
|
{
|
2024-08-09 21:42:04 +03:30
|
|
|
|
await repositoryWrapper.BeginTransaction(cancellationToken);
|
2024-07-06 21:20:10 +03:30
|
|
|
|
var activity = Domain.Entities.Tasks.Activity
|
2023-09-20 11:54:12 +03:30
|
|
|
|
.Create(
|
2023-11-26 16:56:38 +03:30
|
|
|
|
ActivityStatus.Created,
|
2023-12-13 12:05:04 +03:30
|
|
|
|
DateTime.MinValue,
|
2023-11-26 16:56:38 +03:30
|
|
|
|
string.Empty,
|
2023-09-20 11:54:12 +03:30
|
|
|
|
request.Title,
|
|
|
|
|
|
request.Description,
|
|
|
|
|
|
request.Type,
|
|
|
|
|
|
request.IsDisposable,
|
|
|
|
|
|
request.SetFor,
|
|
|
|
|
|
request.HasDisposed,
|
|
|
|
|
|
request.Amount,
|
|
|
|
|
|
request.AmountType,
|
2023-11-18 22:23:23 +03:30
|
|
|
|
complexId,
|
|
|
|
|
|
request.ScheduleType);
|
2023-12-13 12:05:04 +03:30
|
|
|
|
activity.SetUser(request.UserId);
|
2023-09-18 15:41:41 +03:30
|
|
|
|
|
2024-05-20 22:51:01 +03:30
|
|
|
|
activity.SetShiftPlan(request.ShiftPlanId);
|
2023-09-18 09:45:02 +03:30
|
|
|
|
|
2024-08-09 21:42:04 +03:30
|
|
|
|
repositoryWrapper.SetRepository<Domain.Entities.Tasks.Activity>().Add(activity);
|
|
|
|
|
|
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
|
|
|
|
await repositoryWrapper.CommitAsync(cancellationToken);
|
2023-11-26 16:56:38 +03:30
|
|
|
|
return activity.AdaptToLDto();
|
2023-09-20 11:54:12 +03:30
|
|
|
|
}
|
|
|
|
|
|
catch (Exception)
|
2023-09-18 09:45:02 +03:30
|
|
|
|
{
|
2024-08-09 21:42:04 +03:30
|
|
|
|
await repositoryWrapper.RollBackAsync(cancellationToken);
|
2023-09-20 11:54:12 +03:30
|
|
|
|
throw;
|
2023-09-18 09:45:02 +03:30
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|