示例#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();
        }
示例#2
0
        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);
        }
示例#3
0
 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);
 }