public IHttpActionResult Create(Tipo_PagoDTO tipoPagoDTO) { if (!ModelState.IsValid) { return(BadRequest()); } var tipoPago = Mapper.Map <Tipo_PagoDTO, Tipo_Pago>(tipoPagoDTO); _UnityOfWork.TipoPagos.Add(tipoPago); _UnityOfWork.SaveChanges(); tipoPagoDTO.Tipo_PagoId = tipoPago.Tipo_PagoId; return(Created(new Uri(Request.RequestUri + "/" + tipoPago.Tipo_PagoId), tipoPagoDTO)); }
public IHttpActionResult Get() { //La capa de persistencia no debe ser modificada, porque es única para todo canal de atencion de la aplicacion //por lo tanto, a nivel de controlador se debe de hacer las modificaciones. var TipoPagos = _UnityOfWork.TipoPagos.GetAll(); if (TipoPagos == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } var TipoPagoDTO = new List <Tipo_PagoDTO>(); foreach (var tipoPago in TipoPagos) { Tipo_PagoDTO.Add(Mapper.Map <Tipo_Pago, Tipo_PagoDTO>(tipoPago)); } return(Ok(TipoPagoDTO)); }
public IHttpActionResult Update(int id, Tipo_PagoDTO tipoPagoDTO) { if (!ModelState.IsValid) { return(BadRequest()); } var tipoPagoInPersistence = _UnityOfWork.TipoPagos.Get(id); if (tipoPagoInPersistence == null) { return(NotFound()); } Mapper.Map <Tipo_PagoDTO, Tipo_Pago>(tipoPagoDTO, tipoPagoInPersistence); _UnityOfWork.SaveChanges(); return(Ok(tipoPagoDTO)); }