Esempio n. 1
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)
            {
                db.albums.Add(album);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.genreId = new SelectList(db.genres, "genreId", "Name", album.genreId);
            ViewBag.artistId = new SelectList(db.Artists, "artistId", "Name", album.artistId);
            return View(album);
        }
Esempio n. 3
0
 public ActionResult detalles(int id)
 {
     var album = new album {Title="Matisse: " + id };
     return View(album);
 }
 public ActionResult Edit(album album)
 {
     if (ModelState.IsValid)
     {
         db.Entry(album).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.genreId = new SelectList(db.genres, "genreId", "Name", album.genreId);
     ViewBag.artistId = new SelectList(db.Artists, "artistId", "Name", album.artistId);
     return View(album);
 }