Exemplo 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 Json(album, JsonRequestBehavior.AllowGet);
 }
        public ActionResult Create(Album album)
        {
			if (ModelState.IsValid) {
				db.Albums.Add(album);
				db.SaveChanges();
				return RedirectToAction("Index");
			}

            return View(album);
        }
Exemplo n.º 4
0
 public ActionResult Create(Album album)
 {
     if (ModelState.IsValid)
     {
         storeDB.Albums.Add(album);
         storeDB.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.GenreId = new SelectList(storeDB.Genres, "GenreId", "Name", album.GenreId);
     ViewBag.ArtistId = new SelectList(storeDB.Albums, "ArtistId", "Name", album.ArtistId);
     return View(album);
 }
        public ActionResult Create(Album album)
        {
            if (ModelState.IsValid)
            {
                db.Albums.Add(album);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.ArtistID = new SelectList(db.Artists, "ArtistID", "Name", album.ArtistID);
            ViewBag.GenreID = new SelectList(db.Genres, "GenreID", "Name", album.GenreID);
            return View(album);
        }
Exemplo n.º 6
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();
        }
 public ActionResult Edit(Album album)
 {
     if (ModelState.IsValid)
     {
         db.Entry(album).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.ArtistID = new SelectList(db.Artists, "ArtistID", "Name", album.ArtistID);
     ViewBag.GenreID = new SelectList(db.Genres, "GenreID", "Name", album.GenreID);
     return View(album);
 }
Exemplo n.º 8
0
 public ActionResult Edit(Album album)
 {
     if(ModelState.IsValid)
     {
        storeDB.Entry(album).State = System.Data.Entity.EntityState.Modified;
         storeDB.SaveChanges();
         return RedirectToAction("Index");
     }
        ViewBag.GenreId = new SelectList(storeDB.Genres,"GenreId","Name");
         ViewBag.ArtistId = new SelectList(storeDB.Artists, "ArtistId","Name");
         return View(album);
 }