public async Task <Guid> Update(PeopleUpsertDto dto) { using (var scope = new TransactionScope(TransactionScopeOption.Required, TransactionScopeAsyncFlowOption.Enabled)) { var model = dto.ToModel(); await ValidateUpsert(model); await _repository.Update(model); await _addressService.Update(dto.Address, model.Id); scope.Complete(); return(model.Id); } }
public async Task <ActionResult> Post([FromBody] PeopleUpsertDto dto) { try { var id = await _service.Insert(dto); return(StatusCode(201, new InsertedDto(id))); } catch (ValidationException e) { return(StatusCode(400, new ErrorDto(e.Message))); } catch (Exception) { // Erro desconhecido return(StatusCode(500, new ErrorDto("Ocorreu um erro desconhecido na operação"))); } }
public async Task <ActionResult> Put(Guid id, [FromBody] PeopleUpsertDto dto) { try { await _service.Update(dto); return(StatusCode(204)); } catch (ValidationException e) { return(StatusCode(400, new ErrorDto(e.Message))); } catch (Exception) { // Erro desconhecido return(StatusCode(500, new ErrorDto("Ocorreu um erro desconhecido na operação"))); } }
/** * Transforma o Insert/ Update dto em model */ public static PeopleModel ToModel(this PeopleUpsertDto value) { if (value == null) { return(null); } return(new PeopleModel() { Id = value.Id.GetValueOrDefault(), Cellphone = "(xx)" + value.Cellphone, Document = value.Document, Email = value.Email, FatherName = value.FatherName, HomeNumber = value.HomeNumber, Name = value.Name, MotherName = value.MotherName }); }