////************************* FACTURA *****************************************
 ////[HttpPost]
 public ActionResult SaveFactura(int Id)
 {
     var cart = new ShoppingCart();
     //llamo al metodo q guarda la factura
     cart.SaveFactura(Id); // ojo el Id es de User y es arvitrario
     return RedirectToAction("ShowToFactura");
 }
Ejemplo n.º 2
0
 public static ShoppingCart GetCart(HttpContextBase context)
 {
     var cart = new ShoppingCart();
     cart.ShoppingCartId = cart.GetCartId(context);
     return cart;
 }
Ejemplo n.º 3
0
        //************************* FACTURA *****************************************
        //[HttpPost]
        public void SaveFactura(int Id)
        {
            // recibe el id del User
            var objCart = new ShoppingCart();

            // obtengo todo del carrito actual
            var cartAll = db.cart.Where(c => c.idCart == ShoppingCartId);
            // guardo cada items el factura
            foreach (var cart in cartAll)
            {
                var ft = new Factura
                {
                    IdentificatedFactura = ShoppingCartId,
                    ClienteID = Id,
                    Items = new Cart {
                        idCart = ShoppingCartId,
                        MovilPhoneID = cart.MovilPhoneID,
                        Cantidad = cart.Cantidad,
                        PrecioUnidad = cart.PrecioUnidad
                    }
                };

                //Factura f = new Factura();
                //f.IdentificatedFactura = ShoppingCartId;
                //f.ClienteID = Id;
                //f.Items = new Cart
                //{
                //    idCart = ShoppingCartId,
                //    MovilPhoneID = cart.MovilPhoneID,
                //    Cantidad = cart.Cantidad,
                //    PrecioUnidad = cart.PrecioUnidad
                //};

                //saverd factura
                db.facturas.Add(ft);
            }
            db.SaveChanges();
        }
        public ActionResult ShowToFactura()
        {
            //var objCart = new ShoppingCart();
            //string cartCurrent = objCart.GetCartId(this.HttpContext);
            //// obtengo los datos de factura q se han guardado
            //var listElementsFactura = db.facturas.Where(f => f.IdentificatedFactura == cartCurrent);
            //return View(listElementsFactura);

            string textError = null;
            var car = new ShoppingCart();
            try {
                if (car.ShowFactura() == null)
                {
                    ViewBag.error = "si es null";
                }
                else
                {
                    ViewBag.error = "no es null es => " + car.ShowFactura();
                }
            }catch(Exception er){
                textError = er.ToString();
            }

            ViewBag.error = textError;
            return View(car.ShowFactura());
        }