コード例 #1
0
        public void AddToCart(Guitar guitar)
        {
            Cart cart =
                _db.Carts.SingleOrDefault(
                    c => c.Tag == ShoppingCartId &&
                    c.GuitarId == guitar.Id);

            if (cart == null)
            {
                cart = new Cart
                {
                    GuitarId = guitar.Id,
                    Tag = ShoppingCartId,
                    Count = 1,
                    DateCreated = DateTime.Now
                };

                _db.Carts.Add(cart);
            }
            else
            {
                cart.Count++;
            }

            _db.SaveChanges();
        }
コード例 #2
0
 private void FillGuitarViewBag(Guitar g)
 {
     ViewBag.BrandId = new SelectList(db.Brands, "Id", "Name", g.BrandId);
     ViewBag.ColorId = new SelectList(db.Colors, "Id", "Name", g.ColorId);
     ViewBag.ManufacturerId = new SelectList(db.Manufacturers, "Id", "Name", g.ManufacturerId);
     ViewBag.BodyWoodId = new SelectList(db.Woods, "WoodId", "Name", g.BodyWoodId);
     ViewBag.FretboardWoodId = new SelectList(db.Woods, "WoodId", "Name", g.FretboardWoodId);
     ViewBag.FingerboardWoodId = new SelectList(db.Woods, "WoodId", "Name", g.FingerboardWoodId);
 }
コード例 #3
0
 public ActionResult Edit(Guitar guitar)
 {
     if (ModelState.IsValid)
     {
         _db.Entry(guitar).State = EntityState.Modified;
         _db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.BrandId = new SelectList(_db.Brands, "Id", "Name", guitar.BrandId);
     ViewBag.ColorId = new SelectList(_db.Colors, "Id", "Name", guitar.ColorId);
     ViewBag.ManufacturerId = new SelectList(_db.Manufacturers, "ManufacturerId", "Name", guitar.ManufacturerId);
     return View(guitar);
 }
コード例 #4
0
 public NavigationMenuViewModel(Guitar currentGuitar, IEnumerable<BrandInfo> brandsInfo)
 {
     CurrentGuitar = currentGuitar;
     BrandsInfo = brandsInfo;
 }