60 lines
2.3 KiB
C#
60 lines
2.3 KiB
C#
namespace Brizco.Repository.Handlers.Activity;
|
|
|
|
public class UpdateActivityCommandHandler : IRequestHandler<UpdateActivityCommand, bool>
|
|
{
|
|
private readonly IRepositoryWrapper _repositoryWrapper;
|
|
private readonly ICurrentUserService _currentUserService;
|
|
|
|
public UpdateActivityCommandHandler(IRepositoryWrapper repositoryWrapper,ICurrentUserService currentUserService)
|
|
{
|
|
_repositoryWrapper = repositoryWrapper;
|
|
_currentUserService = currentUserService;
|
|
}
|
|
|
|
public async Task<bool> Handle(UpdateActivityCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var task = await _repositoryWrapper.SetRepository<Domain.Entities.Task.Activity>()
|
|
.TableNoTracking.FirstOrDefaultAsync(s => s.Id == request.Id,cancellationToken);
|
|
if (task == null)
|
|
throw new AppException("Task not found", ApiResultStatusCode.NotFound);
|
|
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);
|
|
|
|
try
|
|
{
|
|
await _repositoryWrapper.BeginTransaction(cancellationToken);
|
|
var newTask = Domain.Entities.Task.Activity.Create(
|
|
request.Status,
|
|
request.DoneAt,
|
|
request.PerformanceDescription,
|
|
request.Title,
|
|
request.Description,
|
|
request.Type,
|
|
request.IsRelatedToShift,
|
|
request.IsRelatedToRole,
|
|
request.IsRelatedToPerson,
|
|
request.IsDisposable,
|
|
request.SetFor,
|
|
request.HasDisposed,
|
|
request.Amount,
|
|
request.AmountType,
|
|
complexId);
|
|
|
|
newTask.Id = request.Id;
|
|
|
|
_repositoryWrapper.SetRepository<Domain.Entities.Task.Activity>()
|
|
.Update(newTask);
|
|
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
await _repositoryWrapper.CommitAsync(cancellationToken);
|
|
|
|
return true;
|
|
}
|
|
catch (Exception )
|
|
{
|
|
await _repositoryWrapper.RollBackAsync(cancellationToken);
|
|
throw;
|
|
}
|
|
}
|
|
} |