Beispiel #1
0
        public void AddToCart(Tea tea)
        {
            // Get the matching cart and album instances
            var cartItem = db.Carts.SingleOrDefault(
                c => c.CartId == ShoppingCartId
                && c.TeaId == tea.TeaID);

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists
                cartItem = new Cart
                {
                    TeaId = tea.TeaID,
                    CartId = ShoppingCartId,
                    Count = 1,
                    DateCreated = DateTime.Now
                };
                db.Carts.Add(cartItem);
            }
            else
            {
                // If the item does exist in the cart,
                // then add one to the quantity
                cartItem.Count++;
            }
            // Save changes
            db.SaveChanges();
        }
        public ActionResult Create(Tea tea)
        {
            if (ModelState.IsValid)
            {
                db.Teas.Add(tea);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.TeaTypeID = new SelectList(db.TeaTypes, "TeaTypeID", "Name", tea.TeaTypeID);
            ViewBag.CountryID = new SelectList(db.Countries, "CountryID", "Name", tea.CountryID);
            return View(tea);
        }
 public ActionResult Edit(Tea tea)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tea).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.TeaTypeID = new SelectList(db.TeaTypes, "TeaTypeID", "Name", tea.TeaTypeID);
     ViewBag.CountryID = new SelectList(db.Countries, "CountryID", "Name", tea.CountryID);
     return View(tea);
 }