public static void EnsureSeeded(this MusicStoreDbContext context) { var artists = SampleData.Artists; var genres = SampleData.Genres; var albums = SampleData.GetAlbums(genres, artists); //Ensure we have some status if (!context.Genres.Any()) { context.AddRange(genres); context.SaveChanges(); } //Ensure we create initial Threat List if (!context.Artists.Any()) { context.AddRange(artists); context.SaveChanges(); } if (!context.Albums.Any()) { context.AddRange(albums); context.SaveChanges(); } }
public void AddToCart(Album album) { var cartItem = _context.CartItems.SingleOrDefault(c => c.AlbumId == album.AlbumId && c.ShoppingCartId == _shoppingCartId); if (cartItem == null) { //create a new cart var newCartItem = new CartItem() { ShoppingCartId = _shoppingCartId, AlbumId = album.AlbumId, Count = 1, DateCreated = DateTime.Now }; _context.Add(newCartItem); } else { cartItem.Count++; } _context.SaveChanges(); }