Example #1
0
        public ActionResult DetailFactura(int id)
        {
            GetInidcadores();

            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/Facturas/{id}").Result;
            string     data = response.Content.ReadAsStringAsync().Result;
            FacturaCLS item = JsonConvert.DeserializeObject <FacturaCLS>(data);

            FacturaCLS factura = new FacturaCLS();

            factura.IdFactura   = item.IdFactura;
            factura.Numero      = item.Numero;
            factura.IdCliente   = item.IdCliente;
            factura.IdDireccion = item.IdDireccion;
            factura.Fecha       = item.Fecha;
            factura.Total       = item.Total;

            return(View(factura));
        }
        public ActionResult EditarFactura(FacturaCLS FacturaCLS)
        {
            if (!ModelState.IsValid)
            {
                return(View(FacturaCLS));
            }
            else
            {
                using (var bd = new DBPruebaEntities())
                {
                    //objecto factura
                    FACTURA oFactura = bd.FACTURAs.Where(p => p.IIDFACTURA.Equals(FacturaCLS.IIDFACTURA)).First();
                    oFactura.IIDPERSONA = FacturaCLS.IIDPERSONA;
                    oFactura.FECHA      = FacturaCLS.FECHA;
                    oFactura.NUMFACTURA = FacturaCLS.NUMFACTURA;
                    oFactura.IVA        = FacturaCLS.IVA;
                    oFactura.ESTADO     = int.Parse(FacturaCLS.ESTADO);
                    bd.SaveChanges();

                    DETALLE oDetalle = new DETALLE();

                    foreach (var x in FacturaCLS.DETALLE)
                    {
                        DETALLE oDet = bd.DETALLEs.Where(p => p.IIDDETALLE.Equals(x.IIDDETALLE)).FirstOrDefault();
                        if (oDet != null)
                        {
                            // update information
                            oDet.NOMBREPRODUCTO  = x.NOMBREPRODUCTO;
                            oDet.CANTIDAD        = x.CANTIDAD;
                            oDet.PRECIO_UNITARIO = x.PRECIO_UNITARIO;
                            oDet.TOTAL           = x.TOTAL;
                            oDet.ESTADO          = x.ESTADO;
                            bd.SaveChanges();
                        }
                        else
                        {
                            // insert new data
                            oDetalle.IIDFACTURA      = FacturaCLS.IIDFACTURA;
                            oDetalle.NOMBREPRODUCTO  = x.NOMBREPRODUCTO;
                            oDetalle.CANTIDAD        = x.CANTIDAD;
                            oDetalle.PRECIO_UNITARIO = x.PRECIO_UNITARIO;
                            oDetalle.TOTAL           = x.TOTAL;
                            oDetalle.ESTADO          = 1;
                            bd.DETALLEs.Add(oDetalle);
                            bd.SaveChanges();
                        }
                    }
                }
            }

            return(Json(new { factura = FacturaCLS }));
        }
Example #3
0
        private FacturaCLS GetFactura(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/Facturas/{id}").Result;
            string     data = response.Content.ReadAsStringAsync().Result;
            FacturaCLS item = JsonConvert.DeserializeObject <FacturaCLS>(data);

            return(item);
        }
Example #4
0
        public ActionResult Eliminar(FacturaCLS oFactura)
        {
            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/Facturas/{oFactura.IdFactura}").Result;

            if (response.IsSuccessStatusCode)
            {
                return(RedirectToAction("Index"));
            }

            throw new Exception("Error al eliminar");
        }
Example #5
0
        public ActionResult Eliminar(int id)
        {
            GetInidcadores();

            FacturaCLS factura = new FacturaCLS();

            var item = GetFactura(id);

            factura.IdFactura   = item.IdFactura;
            factura.Numero      = item.Numero;
            factura.IdCliente   = item.IdCliente;
            factura.IdDireccion = item.IdDireccion;
            factura.Fecha       = item.Fecha;
            factura.Total       = item.Total;

            return(View(factura));
        }
Example #6
0
        public ActionResult Guardar(string Numero, int IdCliente, int IdDireccion, DateTime Fecha, decimal Total)
        {
            try
            {
                FacturaCLS factura = new FacturaCLS();

                factura.IdFactura   = 0;
                factura.Numero      = Numero;
                factura.IdCliente   = IdCliente;
                factura.IdDireccion = IdDireccion;
                factura.Fecha       = Fecha;
                factura.Total       = Total;

                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      clienteJson = JsonConvert.SerializeObject(factura);
                HttpContent body        = new StringContent(clienteJson, Encoding.UTF8, "application/json");


                HttpResponseMessage response = httpClient.PostAsync("api/Facturas", body).Result;
                if (response.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index"));
                }


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

            catch (Exception ex)
            {
                return(Json(
                           new
                {
                    success = false,
                    message = ex.InnerException
                }, JsonRequestBehavior.AllowGet));
            }
        }
        // GET: Factura/Create
        public ActionResult CrearFactura(FacturaCLS FacturaCLS)
        {
            int IID = 0;

            if (!ModelState.IsValid)
            {
                return(View(FacturaCLS));
            }
            else
            {
                using (var bd = new DBPruebaEntities())
                {
                    //objecto factura
                    FACTURA oFactura = new FACTURA();
                    oFactura.IIDPERSONA = FacturaCLS.IIDPERSONA;
                    oFactura.FECHA      = FacturaCLS.FECHA;
                    oFactura.NUMFACTURA = FacturaCLS.NUMFACTURA;
                    oFactura.IVA        = FacturaCLS.IVA;
                    oFactura.ESTADO     = int.Parse(FacturaCLS.ESTADO);
                    bd.FACTURAs.Add(oFactura);
                    bd.SaveChanges();
                    IID = oFactura.IIDFACTURA;

                    DETALLE oDetalle = new DETALLE();

                    foreach (var x in FacturaCLS.DETALLE)
                    {
                        oDetalle.IIDFACTURA      = IID;
                        oDetalle.NOMBREPRODUCTO  = x.NOMBREPRODUCTO;
                        oDetalle.CANTIDAD        = x.CANTIDAD;
                        oDetalle.PRECIO_UNITARIO = x.PRECIO_UNITARIO;
                        oDetalle.TOTAL           = x.TOTAL;
                        oDetalle.ESTADO          = 1;
                        bd.DETALLEs.Add(oDetalle);
                        bd.SaveChanges();
                    }
                }
            }

            return(Json(new { draw = IID, factura = FacturaCLS }));
        }