internal async Task <bool> CreateInfraccion(InfraccionDTO ir) { try { HttpClient client = GetClient(); string jfdJson = JsonConvert.SerializeObject(ir); var jfdBuffer = Encoding.UTF8.GetBytes(jfdJson); var jfdByteContent = new ByteArrayContent(jfdBuffer); jfdByteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = await client.PostAsync("Api/Infracciones", jfdByteContent); if (response.IsSuccessStatusCode) { return(true); } else if (response.StatusCode == HttpStatusCode.InternalServerError) { throw new WebApiException(response.ReasonPhrase); } return(false); } catch (Exception ex) { throw; } }
// POST api/<controller> public HttpResponseMessage Post([FromBody] InfraccionDTO inf) { try { Infraccion ir = _mapper.ConvertTo <Infraccion, InfraccionDTO>(inf); _service.NuevaInfraccion(inf.Identificador, inf.Descripcion, inf.PuntosDescontar); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message)); } }