public ActionResult Create() { ViewBag.Genres = storeDB.Genres.OrderBy(g => g.Name).ToList(); ViewBag.Artists = storeDB.Artists.OrderBy(g => g.Name).ToList(); var album = new Album(); return View(album); }
public ActionResult Create(Album album) { if (ModelState.IsValid) { storeDB.Albums.Add(album); storeDB.SaveChanges(); } ViewBag.Genres = storeDB.Genres.OrderBy(g => g.Name).ToList(); ViewBag.Artists = storeDB.Artists.OrderBy(g => g.Name).ToList(); return View(album); }
public void AddToCart(Album album) { var cartItem = storeDB.Carts.SingleOrDefault( c => c.CartId == ShoppingCartId && c.AlbumId == album.AlbumId); if (cartItem == null) { cartItem = new Cart { AlbumId = album.AlbumId, CartId = ShoppingCartId, Count = 1, DateCreated = DateTime.Now }; storeDB.Carts.Add(cartItem); } else { cartItem.Count++; } storeDB.SaveChanges(); }