public ActionResult Create()
 {
     ViewBag.Genres = storeDB.Genres.OrderBy(g => g.Name).ToList();
     ViewBag.Artists = storeDB.Artists.OrderBy(a => a.Name).ToList();
     var album = new Album();
     return View(album);
 }
예제 #2
0
        public void AddToCart(Album album)
        {
            // Get the matching cart and album instances
            var cartItem = storeDB.Carts.SingleOrDefault(c => c.CartId == ShoppingCartId && c.AlbumId == album.AlbumId);

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists
                cartItem = new Cart
                {
                    AlbumId = album.AlbumId,
                    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(Album album)
 {
     if (ModelState.IsValid)
     {
         //Save Album
         storeDB.Albums.Add(album);
         storeDB.SaveChanges();
         return RedirectToAction("Index");
     }
     // Invalid – redisplay with errors
     ViewBag.Genres = storeDB.Genres.OrderBy(g => g.Name).ToList();
     ViewBag.Artists = storeDB.Artists.OrderBy(a => a.Name).ToList();
     return View(album);
 }