public IHttpActionResult Add([FromBody] Catalogo catalogoDto) { try { if (!ModelState.IsValid) { response.Status = Constants.ResponseStatus.error; response.Code = HttpStatusCode.BadRequest; response.Message = Constants.ErrorMessage.bad_request; return(Content(HttpStatusCode.BadRequest, response)); } else { t_catalogo catalogo = Mapper.Map <Catalogo, t_catalogo>(catalogoDto); repository.Add(catalogo); repository.Save(); catalogoDto.id_articulo = catalogo.id_articulo; return(Created(new Uri($"{Request.RequestUri}/{catalogoDto.id_articulo}"), catalogoDto)); } } catch (Exception ex) { response.Status = Constants.ResponseStatus.error; response.Message = Constants.ErrorMessage.internal_server_error; return(Content(HttpStatusCode.InternalServerError, response)); } }
public IHttpActionResult getSingle(int id) { try { t_catalogo catalogo = repository.GetSingle(id); Catalogo catalogoDto = Mapper.Map <t_catalogo, Catalogo>(catalogo); response = catalogoDto; return(Ok(response)); } catch (Exception ex) { response.Status = Constants.ResponseStatus.error; response.Message = Constants.ErrorMessage.internal_server_error; return(Content(HttpStatusCode.InternalServerError, response)); } }