public async Task <string> Handle(CreateEbatchSheetCommand request, CancellationToken cancellationToken) { _logger.LogInformation("CREATE_NEW_EBATCHSHEET : {@request} ", request); var newEbatch = new EbatchSheet(); newEbatch.Create(request); await _cosmosStore.AddAsync(newEbatch); await _ebatchSheetEmailSender.SendEmail(newEbatch); return(newEbatch.Id); }
public async Task <string> Handle(UpdateEbatchSheetCommand request, CancellationToken cancellationToken) { _logger.LogInformation(nameof(UpdateEbatchSheetCommandHandler) + "UPDATE_EBATCHSHEET: {requestId} - {@BODY} ", request.Id, request); var ebatchSheet = await _cosmosStore.FindAsync(request.Id, Constants.EBATCH_SHEET_PARTITON_KEY); var user = _httpContext.HttpContext?.User; if (ebatchSheet != null) { var currentState = ebatchSheet.CurrentState; var requestedState = request.CurrentState; ebatchSheet.UpdateDataWithoutChangingState(request); if (!requestedState.Equals(currentState)) { if (user.IsInRole(UserRole.AdminTeam)) { ebatchSheet.ChangeState(requestedState); } else { ebatchSheet.ProceedNextState(requestedState); } } var result = await _cosmosStore.UpdateAsync(ebatchSheet); if (!currentState.Equals(result.Entity.CurrentState)) { await _ebatchSheetEmailSender.SendEmail(ebatchSheet); } return(request.Id); } else { var exception = new NotFoundException($"EBATCHSHEET", request.Id); _logger.LogError(exception, $"[UpdateEbatchSheetCommandHandler] Ebatchsheet {request.Id} not found"); throw exception; } }