public ActionResult <ItensProposta> PutItensProposta(Guid id, ItensProposta itensProposta) { if (id != itensProposta.Id) { return(BadRequest()); } try { var result = _itensPropostaBusiness.Update(itensProposta); if (result.IsValid) { _unitOfWork.Commit(); return(CreatedAtAction("GetAnuncio", new { id = itensProposta.Id }, itensProposta)); } _unitOfWork.Rollback(); return(BadRequest(result.ErrorMessage)); } catch (DbUpdateConcurrencyException) { _unitOfWork.Rollback(); if (!ItemPropostaExists(id)) { return(NotFound()); } else { throw; } } }
public ActionResult <ItensProposta> PostItensProposta([FromBody] ItensProposta itensProposta) { try { var result = _itensPropostaBusiness.Insert(itensProposta); if (result.IsValid) { _unitOfWork.Commit(); return(CreatedAtAction("GetItensProposta", new { id = itensProposta.Id }, itensProposta)); } _unitOfWork.Rollback(); return(BadRequest(result)); } catch (DbUpdateException ex) { _unitOfWork.Rollback(); if (ItemPropostaExists(itensProposta.Id)) { return(Conflict(ex.Message)); } else { throw ex; } } catch (Exception ex) { _unitOfWork.Rollback(); return(BadRequest(ex.Message)); } }