public async Task <PenaltyDTO> Get(Guid id) { var result = await this.Handler.Execute(_log, async() => { var repositoryResult = await _penaltyRepository.Get(id); if (repositoryResult == null) { throw new RecordNotFoundException("Penalty", id); } return(_penaltyMapper.ToDto(repositoryResult)); }); return(result); }
public async Task Handle( PenaltyOperationCreated message, CancellationToken cancellationToken) { _logger.LogInformation($"PenaltyOperationCreated for penalty {message.PenaltyId} has received"); var penalty = await _penaltyRepository.Get(message.PenaltyId, cancellationToken); if (penalty == null) { throw new InvalidOperationException($"Penalty: {message.PenaltyId} not found"); } await _penaltyProcessor.Process(penalty, cancellationToken); await _penaltyRepository.Save(penalty); }
public async Task <IActionResult> CancelPenalty( [FromServices] IPenaltyRepository repository, [FromRoute] Guid id, CancellationToken cancellationToken) { var penalty = await repository.Get(id, HttpContext.GetGuildId(), cancellationToken); if (penalty == null) { throw new ApiException(HttpStatusCode.NotFound, ErrorCodes.PenaltyNotFound, $"Penalty {id} not found"); } try{ penalty.MakeCancel(); await repository.Save(penalty); } catch (InvalidOperationException) { throw new ApiException(HttpStatusCode.Conflict, ErrorCodes.IncorrectOperation, $"Incorrect penalty state"); } return(Ok(new { })); }