Esempio n. 1
0
 public ActionResult Create(Productt productt)
 {
     if (ModelState.IsValid)
     {
         db.Productts.Add(productt);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View());
 }
Esempio n. 2
0
        public ActionResult AddItem(long productid, int quantity)
        {
            ProductDAO      dao     = new ProductDAO();
            Productt        product = dao.GetID(productid);
            List <CartItem> lst     = new List <CartItem>();
            var             cart    = Session[CartSession];

            if (cart != null)
            {
                lst = (List <CartItem>)cart;
                if (lst.Where(x => x.Product.ID == productid).SingleOrDefault() != null)
                {
                    //foreach (var item in lst)
                    //{
                    //    if (item.Product.ID == productid)
                    //    {
                    lst.Where(x => x.Product.ID == productid).SingleOrDefault().Quantity += quantity;
                    //    }

                    //}
                }
                else
                {
                    var c = new CartItem();
                    c.Product  = product;
                    c.Quantity = quantity;
                    lst.Add(c);
                }
                Session[CartSession] = lst;
            }
            else
            {
                var c = new CartItem();
                c.Product  = product;
                c.Quantity = quantity;
                lst.Add(c);
                Session[CartSession] = lst;
            }
            return(RedirectToAction("Index"));
        }