public void AddToCart(Album album)
        {
            //get matching cart and album instances
            var cartItem = storeDB.Carts.SingleOrDefault(
                c => c.CartID == ShoppingCartID &&
                c.AlbumId == album.AlbumId);

            if (cartItem == null)
            {
                //create 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);
            } // end if

            else
            {
                //if cartItem does exist in the cart then add one to the qty
                cartItem.Count++;
            } // end else
            storeDB.SaveChanges();
        }     // end method AddToCart
Exemple #2
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();
        }
Exemple #3
0
        /*
         * AddToCart lấy một Album làm thông số và thêm nó vào giỏ hàng của người dùng.
         * Vì bảng Giỏ hàng theo dõi số lượng cho
         * mỗi album, nó bao gồm logic để tạo một hàng mới nếu cần hoặc chỉ tăng số lượng nếu người dùng đã
         * đã đặt hàng một bản sao của album
         */
        public void AddToCart(Album album)
        {
            // Nhận các phiên bản album và giỏ hàng phù hợp
            var cartItem = storeDB.Carts.SingleOrDefault(
                c => c.CartId == ShoppingCartId &&
                c.AlbumId == album.AlbumId);

            if (cartItem == null)
            {
                // Tạo một mặt hàng mới trong giỏ hàng nếu không có mặt hàng nào trong giỏ hàng
                cartItem = new Cart()
                {
                    AlbumId     = album.AlbumId,
                    CartId      = ShoppingCartId,
                    Count       = 1,
                    DateCreated = DateTime.Now
                };
                storeDB.Carts.Add(cartItem);
            }
            else
            {
                // Nếu mặt hàng tồn tại trong giỏ hàng, thì hãy thêm một mặt hàng vào số lượng
                cartItem.Count++;
            }
            storeDB.SaveChanges();
        }
Exemple #4
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();
        }
Exemple #5
0
 public void SaveNewOrder(Order order)
 {
     storeDB.Orders.Add(order);
     storeDB.SaveChanges();
 }
 public void Delete(Album album)
 {
     storeDB.Albums.Remove(album);
     storeDB.SaveChanges();
 }
Exemple #7
0
        //private static Labo6Context _context;

        //public PopulateDatabase(Labo6Context context)
        //{
        //    _context = context;
        //}

        public static void EnsurePopulated(MusicStoreEntities context)
        {
            context.Database.EnsureCreated();
            //Labo6Context context = app.ApplicationServices
            //    .GetRequiredService<Labo6Context>();
            //if (!context.Genres.Any())

            Genre g1 = new Genre {
                Name = "Rock", Description = "rock n roll"
            };
            Genre g2 = new Genre {
                Name = "Jazz", Description = "jazzy music"
            };
            Genre g3 = new Genre {
                Name = "disco", Description = "disco music"
            };
            Genre g4 = new Genre {
                Name = "Métal", Description = "Métal music"
            };
            Genre g5 = new Genre {
                Name = "dance", Description = "danse music"
            };
            Genre g6 = new Genre {
                Name = "Latin", Description = "salsa music"
            };
            Genre g7 = new Genre {
                Name = "Blue", Description = "Blue music"
            };
            Genre g8 = new Genre {
                Name = "India Music", Description = "india music"
            };

            context.Genres.Add(g1);
            context.Genres.Add(g2);
            context.Genres.Add(g3);
            Artist As1 = new Artist {
                Name = "dire street"
            };
            Artist As2 = new Artist {
                Name = "Celine dione"
            };
            Artist As3 = new Artist {
                Name = "David guetta"
            };

            context.Artises.Add(As1);
            context.Artises.Add(As2);
            context.Artises.Add(As3);
            Album a1 = new Album {
                Title = "AMOUR INVISIBLE", Price = 10, Genre = g1, Artist = As1, AlbumArtUrl = "www.music.fr"
            };
            Album a2 = new Album {
                Title = "GIVE ME YOUR HEART", Price = 10, Genre = g2, Artist = As2, AlbumArtUrl = "www.music.fr"
            };
            Album a3 = new Album {
                Title = "I need you", Price = 10, Genre = g3, Artist = As3, AlbumArtUrl = "www.music.fr"
            };

            context.Albums.Add(a1); context.Albums.Add(a2); context.Albums.Add(a3);

            context.SaveChanges();
        }