Пример #1
0
        private static void AddToCart(Book book, Cart cart, int quantity)
        {
            CartItem newCartItem = new CartItem();

            newCartItem.Book      = book;
            newCartItem.TimeAdded = DateTime.Now;
            newCartItem.Cart      = cart;
            newCartItem.Quantity  = quantity;

            context.CartItems.Add(newCartItem);
            context.SaveChanges();
        }
Пример #2
0
        public static Cart CreateCart(UserDetail user)
        {
            Cart newCart = new Cart
            {
                UserDetail  = user,
                PaymentMode = null,
                CheckedOut  = false
            };

            context.Carts.Add(newCart);
            context.SaveChanges();

            return(newCart);
        }
Пример #3
0
 public static void DeleteBook(string ISBN)
 {
     using (BookStoreEntities entities = new BookStoreEntities())
     {
         Book order = entities.Books.Where(p => p.ISBN == ISBN).First();
         entities.Books.Remove(order);
         entities.SaveChanges();
     }
 }
Пример #4
0
        public static void Updatebook(String ISBN,
                                      decimal price, int stock)
        {
            using (BookStoreEntities entities = new BookStoreEntities())
            {
                Book book = entities.Books.Where(p => p.ISBN == ISBN).First();
                book.Price      = price;
                book.StockLevel = stock;

                entities.SaveChanges();
            }
        }
Пример #5
0
        public static void AddNewUser(string username, string email, string name, string contact)
        {
            UserDetail newUser = new UserDetail
            {
                UserName      = username,
                Email         = email,
                Name          = name,
                ContactNumber = contact
            };

            context.UserDetails.Add(newUser);
            context.SaveChanges();
        }
Пример #6
0
 public static void AddDiscount(Category category, DateTime startDate,
                                DateTime endDate, decimal discountPercent)
 {
     if (startDate > endDate)
     {
         throw new InvalidObjectParams("Discount start date should be before end date");
     }
     else if (discountPercent < 0 || discountPercent > 100)
     {
         throw new InvalidObjectParams("Discount percent should be between 0 and 100");
     }
     else
     {
         Discount discount = new Discount();
         discount.Category        = category;
         discount.StartDate       = startDate;
         discount.EndDate         = endDate;
         discount.DiscountPercent = Math.Round(discountPercent, 2);
         context.Discounts.Add(discount);
         context.SaveChanges();
     }
 }