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();
        }
        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();
            }
        }
        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();
     }
 }