示例#1
0
        public void AddToCart(Drinks drink)
        {
            // Get the matching cart and drink instances
            var cartItem = storeDB.Carts.SingleOrDefault(
                c => c.CartId == ShoppingCartId
                && c.DrinksId == drink.DrinksId);

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists
                cartItem = new Cart
                {
                    DrinksId = drink.DrinksId,
                    CartId = ShoppingCartId,
                    Count = 1,
                    DateCreated = DateTime.Now
                };

                storeDB.Carts.Add(cartItem);
            }
            else
            {
                // If the item does exist in the cart, then add one to the quantity
                cartItem.Count++;
            }

            // Save changes
            storeDB.SaveChanges();
        }
        public ActionResult Create(Drinks drinks)
        {
            if (ModelState.IsValid)
            {
                db.Drink.Add(drinks);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(drinks);
        }
 // will likely need to be an int id to correspond to the id of the database entity
 // GET: /Store/Drinks
 public ActionResult Drinks(string drink)
 {
     // Needs to get a list of all available drinks at an Establishment
     var drinkModel = new Drinks { name = drink };
     return View(drinkModel);
 }
 public ActionResult Edit(Drinks drinks)
 {
     if (ModelState.IsValid)
     {
         db.Entry(drinks).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(drinks);
 }