예제 #1
0
        public void AddToCart(Album album)
        {
            var cartItem = storeDB.Carts.SingleOrDefault(
                c => c.CartId == shoppingCartId &&
                c.AlbumId == album.AlbumId);

            if (cartItem == null)
            {
                // Create a new cart item
                cartItem = new Cart
                {
                    AlbumId = album.AlbumId,
                    CartId = shoppingCartId,
                    Count = 1,
                    DateCreated = DateTime.Now
                };
                storeDB.AddToCarts(cartItem);
            }
            else
            {
                // Add one to the quantity
                cartItem.Count++;
            }

            // Save it
            storeDB.SaveChanges();
        }
        public ActionResult Create(Album album)
        {
            if (ModelState.IsValid)
            {

                //Save Album
                storeDB.AddToAlbums(album);
                storeDB.SaveChanges();

                return RedirectToAction("Index");

            }

            // Invalid – redisplay with errors
            var viewModel = new StoreManagerViewModel
            {
                Album = album,
                Genres = storeDB.Genres.ToList(),
                Artists = storeDB.Artists.ToList()
            };

            return View(viewModel);
        }
 /// <summary>
 /// Create a new Album object.
 /// </summary>
 /// <param name="albumId">Initial value of the AlbumId property.</param>
 /// <param name="genreId">Initial value of the GenreId property.</param>
 /// <param name="artistId">Initial value of the ArtistId property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 /// <param name="price">Initial value of the Price property.</param>
 public static Album CreateAlbum(global::System.Int32 albumId, global::System.Int32 genreId, global::System.Int32 artistId, global::System.String title, global::System.Decimal price)
 {
     Album album = new Album();
     album.AlbumId = albumId;
     album.GenreId = genreId;
     album.ArtistId = artistId;
     album.Title = title;
     album.Price = price;
     return album;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Albums EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToAlbums(Album album)
 {
     base.AddObject("Albums", album);
 }