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);
        }
Ejemplo n.º 3
0
        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();
        }