Наследование: System.Data.Objects.DataClasses.EntityObject
 public AlbumSelectListViewModel(Album album, 
                                 IEnumerable artists, 
                                 IEnumerable genres) {
     Album = album;
     Artists = new SelectList(artists, "ArtistID", "Name", album.ArtistId);
     Genres = new SelectList(genres, "GenreID", "Name", album.GenreId);
 }
 //编辑
 public ActionResult Edit(int id)
 {
     MvcMusicStore.Models.Album album = storeDB.Albums.Find(id);
     ViewBag.GenreId  = new SelectList(storeDB.Genres, "GenreId", "Name", album.GenreId);
     ViewBag.ArtistId = new SelectList(storeDB.Artists, "ArtistId", "Name", album.ArtistId);
     return(View(album));
 }
Пример #3
0
        public void AddToCart(Album album)
        {
            // Get the matching cart and album instances
            Cart cartItem = Cart.FindByCartIdAlbum(ShoppingCartId, album);

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists
                cartItem = new Cart
                {
                    Album = album,
                    CartId = ShoppingCartId,
                    Count = 1,
                    DateCreated = DateTime.Now
                };
            }
            else
            {
                // If the item does exist in the cart, then add one to the quantity
                cartItem.Count++;
            }

            // Save changes
            cartItem.Save();
        }
        public void AddToCart(Album album)
        {
            // Get the matching cart and album instances
            //            var cartItem = storeDB.Carts.SingleOrDefault(
            //c => c.CartId == ShoppingCartId
            //&& c.AlbumId == album.Id);
            var cartItem = _cartsPersister.LoadByAlbumAndShoppingCartId(album.Id, ShoppingCartId);

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists
                cartItem = new Cart
                {
                    Album = album,
                    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();
            _cartsPersister.Store(cartItem);
        }
Пример #5
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();
        }
Пример #6
0
        public void AddToCart(Album album)
        {
            using (var tx = storeContext.Session.BeginTransaction())
            {
                var cartItem = storeContext.Carts.SingleOrDefault(
                    c => c.CartId == shoppingCartId &&
                         c.Album == album);

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

                // Save it
                storeContext.Session.Save(cartItem);

                tx.Commit();
            }
        }
Пример #7
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();
        }
Пример #8
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();
        }
 static void AssertAlbumVmMatchesAlbum(Album album, AlbumVm albumVm)
 {
     Assert.That(album.AlbumId, Is.EqualTo(albumVm.AlbumId));
     Assert.That(album.GenreId, Is.EqualTo(albumVm.GenreId));
     if (album.Genre != null) Assert.That(album.Genre.Name, Is.EqualTo(albumVm.GenreName));
     Assert.That(album.ArtistId, Is.EqualTo(albumVm.ArtistId));
     if (album.Artist != null) Assert.That(album.Artist.Name, Is.EqualTo(albumVm.ArtistName));
     Assert.That(album.Title, Is.EqualTo(albumVm.Title));
     Assert.That(album.Price, Is.EqualTo(albumVm.Price));
     Assert.That(album.AlbumArtUrl, Is.EqualTo(albumVm.AlbumArtUrl));
 }
 public ActionResult DeleteConfirmed(int id)
 {
     try
     {
         MvcMusicStore.Models.Album album = storeDB.Albums.Find(id);
         storeDB.Albums.Remove(album);
         storeDB.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Пример #11
0
 AlbumVm AlbumToAlbumVm(Album album)
 {
     if (album == null) return null;
     return new AlbumVm
            {
                AlbumId = album.AlbumId,
                GenreId = album.GenreId,
                GenreName = album.Genre.Name,
                ArtistId = album.ArtistId,
                ArtistName = album.Artist.Name,
                Title = album.Title,
                Price = album.Price,
                AlbumArtUrl = album.AlbumArtUrl,
            };
 }
Пример #12
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();
 }
Пример #13
0
        public async Task AddToCart(Album album)
        {
            var cartItem = await GetCartItem(album.AlbumId);

            if (cartItem == null)
            {
                cartItem = new Cart
                {
                    AlbumId = album.AlbumId,
                    CartId = _cartId,
                    Count = 1,
                    DateCreated = DateTime.Now
                };

                _storeContext.Carts.Add(cartItem);
            }
            else
            {
                cartItem.Count++;
            }
        }
Пример #14
0
 public void AddToCart(Album album)
 {
     // this runs in memory, there is no database queries here, mister!
     var albumLine = Lines.FirstOrDefault(line => line.Album.Id == album.Id);
     if (albumLine != null)
     {
         albumLine.Quantity++;
         return;
     }
     Lines.Add(new ShoppingCartLine
     {
         Album = new ShoppingCartLine.ShoppingCartLineAlbum
         {
             Id = album.Id,
             Title = album.Title
         },
         DateCreated = DateTime.Now,
         Price = album.Price,
         Quantity = 1
     });
 }
Пример #15
0
        public ActionResult CreateAlbum()
        {
            var album = new Album();

            if (!TryUpdateModel(album, prefix: null, includeProperties: null, excludeProperties: new[] { "Genre", "Artist", "OrderDetails" }))
            {
                // Return the model errors
                return new ApiResult(ModelState);
            }

            // Save the changes to the DB
            _storeContext.Albums.Add(album);
            _storeContext.SaveChanges();

            // TODO: Handle missing record, key violations, concurrency issues, etc.

            return new ApiResult
            {
                Data = album.AlbumId,
                Message = "Album created successfully."
            };
        }
        public ActionResult Create(Album album)
        {
            try
            {
                //Save Album
                storeDB.AddToAlbums(album);
                storeDB.SaveChanges();

                return Redirect("/");
            }
            catch
            {
                //Invalid - redisplay with errors

                var viewModel = new StoreManagerViewModel
                {
                    Album = album,
                    Genres = storeDB.Genres.ToList(),
                    Artists = storeDB.Artists.ToList()
                };

                return View(viewModel);
            }
        }
Пример #17
0
 /// <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;
 }
Пример #18
0
 /// <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);
 }
 /// <summary>
 /// 删除操作
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public ActionResult Delete(int id)
 {
     MvcMusicStore.Models.Album album = storeDB.Albums.Find(id);
     return(View(album));
 }
Пример #20
0
 public ActionResult Details(int id)
 {
     var album = new Album { Title = "Album " + id };
     return View(album);
 }
Пример #21
0
 public void AddAlbum(Album album)
 {
     album.Genre = this;
     Albums.Add(album);
 }