public async Task <DTO.StateOutput> UpdateEntityAsync(long id, DTO.StateInput entity) { try { await TransactionHandler.BeginTransactionAsync(); var foundState = await StateRepository.GetEntityByIdAsync(id); if (foundState == null) { throw new NotFoundException("This state does not exist."); } foundState.Name = entity.Name; await StateRepository.UpdateEntityAsync(foundState); await TransactionHandler.CommitTransactionAsync(); return(Mapper.Map <DTO.StateOutput>(foundState)); } catch { await TransactionHandler.RollbackTransactionAsync(); throw; } finally { await TransactionHandler.DisposeTransactionAsync(); } }
public async Task <IActionResult> PutStateAsync([FromQuery] long stateId, [FromBody] DTO.StateInput state) { var insertedState = await StateManager.UpdateEntityAsync(stateId, state); return(Ok(new DTO.SuccessResponse <DTO.StateOutput> { Success = true, Content = insertedState })); }
public async Task <DTO.StateOutput> InsertEntityAsync(DTO.StateInput entity) { try { await TransactionHandler.BeginTransactionAsync(); var convertedState = Mapper.Map <DAO.State>(entity); var insertedState = await StateRepository.InsertEntityAsync(convertedState); await TransactionHandler.CommitTransactionAsync(); return(Mapper.Map <DTO.StateOutput>(insertedState)); } catch { await TransactionHandler.RollbackTransactionAsync(); throw; } finally { await TransactionHandler.DisposeTransactionAsync(); } }