예제 #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 IEnumerable<IResponse> Create(Album album)
		{
			if (ModelState.IsValid)
			{
				db.Albums.Add(album);
				db.SaveChanges();
				yield return RedirectToAction("Index");
			}

			ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name", album.GenreId);
			ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "Name", album.ArtistId);
			yield return View(album);
		}
		public IEnumerable<IResponse> Edit(Album album)
		{
			if (ModelState.IsValid)
			{
				db.Entry(album).State = EntityState.Modified;
				db.SaveChanges();
				yield return RedirectToAction("Index");
			}
			ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name", album.GenreId);
			ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "Name", album.ArtistId);
			yield return View(album);
		}