Exemplo n.º 1
0
        private DetalleFacturaCLS GetDetalleFactura(int id)
        {
            HttpClient httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri(baseURL);
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session["token"].ToString());

            HttpResponseMessage response     = httpClient.GetAsync($"api/DetalleFacturas/{id}").Result;
            string            data           = response.Content.ReadAsStringAsync().Result;
            DetalleFacturaCLS detalleFactura = JsonConvert.DeserializeObject <DetalleFacturaCLS>(data);

            return(detalleFactura);
        }
Exemplo n.º 2
0
        public ActionResult Editar(
            int IdDetalleFactura,
            int IdFactura,
            int IdServicio,
            int Cantidad,
            Nullable <bool> Entregado
            )
        {
            try
            {
                DetalleFacturaCLS detalleFactura = new DetalleFacturaCLS();
                detalleFactura.IdDetalleFactura = IdDetalleFactura;
                detalleFactura.IdFactura        = IdFactura;
                detalleFactura.IdServicio       = IdServicio;
                detalleFactura.Cantidad         = Cantidad;
                detalleFactura.Entregado        = Entregado;

                HttpClient httpClient = new HttpClient();
                httpClient.BaseAddress = new Uri(baseURL);
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session["token"].ToString());

                string      detalleFacturaJson = JsonConvert.SerializeObject(detalleFactura);
                HttpContent body = new StringContent(detalleFacturaJson, Encoding.UTF8, "application/json");


                HttpResponseMessage response = httpClient.PutAsync($"api/DetalleFacturas/{IdDetalleFactura}", body).Result;
                if (response.IsSuccessStatusCode)
                {
                    /*return Json(
                     *  new
                     *  {
                     *      success = true,
                     *      message = "Cliente modificado satisfactoriamente"
                     *  }, JsonRequestBehavior.AllowGet);*/
                    return(RedirectToAction("Index"));
                }
                throw new Exception("Error al guardar");
            }
            catch (Exception ex)
            {
                return(Json(
                           new
                {
                    success = false,
                    message = ex.InnerException
                }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 3
0
        public ActionResult DetailDetalleFactura(int id)
        {
            GetInidcadores();

            DetalleFacturaCLS detalleFactura = new DetalleFacturaCLS();

            var item = GetDetalleFactura(id);

            detalleFactura.IdDetalleFactura = item.IdDetalleFactura;
            detalleFactura.IdFactura        = item.IdFactura;
            detalleFactura.IdServicio       = item.IdServicio;
            detalleFactura.Cantidad         = item.Cantidad;
            detalleFactura.Entregado        = item.Entregado;

            return(View(detalleFactura));
        }
Exemplo n.º 4
0
        public ActionResult Eliminar(DetalleFacturaCLS detalleFactura)
        {
            HttpClient httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri(baseURL);
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session["token"].ToString());

            HttpResponseMessage response = httpClient.DeleteAsync($"api/DetalleFacturas/{detalleFactura.IdDetalleFactura}").Result;

            if (response.IsSuccessStatusCode)
            {
                /*return Json(
                 *  new
                 *  {
                 *      success = true,
                 *      message = "El cliente fue eliminado satisfactoriamente"
                 *  }, JsonRequestBehavior.AllowGet);*/
                return(RedirectToAction("Index"));
            }

            throw new Exception("Error al eliminar");
        }