Ejemplo n.º 1
0
        internal async Task <bool> RegistrarInfraccion(InfraccionRegistradaDTO 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/RegistrarInfraccion", jfdByteContent);

                if (response.IsSuccessStatusCode)
                {
                    return(true);
                }
                else if (response.StatusCode == HttpStatusCode.InternalServerError)
                {
                    throw new WebApiException(response.ReasonPhrase);
                }
                return(false);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Post([FromBody] InfraccionRegistradaDTO inf)
        {
            try
            {
                Infraccion ir = _mapper.ConvertTo <Infraccion, InfraccionDTO>(inf.infraccion);

                _service.RegistrarInfraccion(ir, inf.vehiculo.Matricula);
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message));
            }
        }
Ejemplo n.º 3
0
 private async void Button_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         InfraccionRegistradaDTO ir = new InfraccionRegistradaDTO()
         {
             infraccion = (InfraccionDTO)comboInfraccion.SelectedItem, vehiculo = _v
         };
         if (await _webApiClient.RegistrarInfraccion(ir))
         {
             MessageBox.Show("Infraccion Registrada");
             this.Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }