Ejemplo n.º 1
0
        public IActionResult Añadir(int id)
        {
            DataContextProducts db             = HttpContext.RequestServices.GetService(typeof(DataContextProducts)) as DataContextProducts;
            List <Product>      listaProductos = db.GetAllProducts();

            if (SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart") == null)
            {
                List <Item> cart = new List <Item>();
                cart.Add(new Item {
                    Product = db.find(id, listaProductos), Quantity = 1
                });
                SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart);
            }
            else
            {
                List <Item> cart  = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart");
                int         index = isExist(id);
                if (index != -1)
                {
                    cart[index].Quantity++;
                }
                else
                {
                    cart.Add(new Item {
                        Product = db.find(id, listaProductos), Quantity = 1
                    });
                }
                SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart);
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public IActionResult Index()
        {
            DataContextProducts db             = HttpContext.RequestServices.GetService(typeof(DataContextProducts)) as DataContextProducts;
            List <Product>      listaProductos = db.GetAllProducts();
            List <Product>      perifericos    = new List <Product>();

            foreach (Product p in listaProductos)
            {
                if (p.Tipo.Contains("periferico"))
                {
                    perifericos.Add(p);
                }
            }
            return(View(model: perifericos));
        }
Ejemplo n.º 3
0
        public IActionResult Index()
        {
            DataContextProducts db             = HttpContext.RequestServices.GetService(typeof(DataContextProducts)) as DataContextProducts;
            List <Product>      listaProductos = db.GetAllProducts();
            List <Product>      componentes    = new List <Product>();

            foreach (Product p in listaProductos)
            {
                if (p.Tipo.Contains("componente"))
                {
                    componentes.Add(p);
                    //COMPONENTES ES UNA LISTA DE PRODUCTOS Y TU LA TRATAS COMO LISTA DE ITEMS MELON
                }
            }
            return(View(model: componentes));
        }