예제 #1
0
        public static void CheckOut(string UName, int bookid, int quantity, float fprice)
        {
            int LastOrderID;
            int g;

            using (TransactionScope Ts = new TransactionScope())
            {
                LastOrderID = GetLastOrderID() + 1;
                //To add order
                using (BookshopModel entities = new BookshopModel())
                {
                    OrderDetail order = new OrderDetail()
                    {
                        OrderID    = LastOrderID,
                        UserName   = UName,
                        BookID     = bookid,
                        Quantity   = quantity,
                        finalprice = (decimal)fprice,
                        Totalprice = (decimal)(quantity * (decimal)fprice)
                    };
                    entities.OrderDetails.Add(order);

                    var  q = from x in entities.Books where x.BookID == bookid select x;
                    Book b = q.First();
                    g       = (int)b.Stock;
                    g       = g - quantity;
                    b.Stock = g;
                    entities.SaveChanges();
                }

                /*scribbly here*/
                // Transaction.Current.TransactionCompleted += new TransactionCompletedEventHandler(Current_TransactionCompleted);
                Ts.Complete();
            }
        }
예제 #2
0
 //Todeletebook
 public static void DeleteBook(int bookid)
 {
     using (BookshopModel entities = new BookshopModel())
     {
         Book book = entities.Books.Where(p => p.BookID == bookid).First <Book>();
         entities.Books.Remove(book);
         entities.SaveChanges();
     }
 }
예제 #3
0
 //discount
 public static void discount(decimal discount)
 {
     using (BookshopModel entities = new BookshopModel())
     {
         foreach (Book b in entities.Books.ToList())
         {
             b.finalprice = b.Price * (1 - (discount / 100));
             b.SWdiscount = 1 - discount / 100;
             entities.SaveChanges();
         }
     }
 }
예제 #4
0
 //Toaddcategory
 public static void SaveCategory(string category)
 {
     using (BookshopModel entities = new BookshopModel())
     {
         Category c = new Category()
         {
             Name = category,
         };
         entities.Categories.Add(c);
         entities.SaveChanges();
     }
 }
예제 #5
0
 //Toupdatebook
 public static void UpdateBook(int bookid, string title, int categoryid, string isbn, string author, int stock, decimal finalprice,
                               string synopsis)
 {
     using (BookshopModel entities = new BookshopModel())
     {
         Book book = entities.Books.Where(p => p.BookID == bookid).First <Book>();
         book.Title      = title;
         book.CategoryID = categoryid;
         book.ISBN       = isbn;
         book.Author     = author;
         book.Stock      = stock;
         book.finalprice = finalprice;
         book.Synopsis   = synopsis;
         entities.SaveChanges();
     }
 }
예제 #6
0
        //To add Book

        public static void Savebook(string title, int categoryid, string isbn, string author, int stock, decimal price,
                                    string synopsis, decimal discount)
        {
            using (BookshopModel entities = new BookshopModel())
            {
                Book b = new Book()
                {
                    Title      = title,
                    CategoryID = categoryid,
                    ISBN       = isbn,
                    Author     = author,
                    Stock      = stock,
                    Price      = price,
                    Synopsis   = synopsis,
                    SWdiscount = 1 - (discount / 100),
                    finalprice = price * (1 - (discount / 100)),
                };
                entities.Books.Add(b);
                entities.SaveChanges();
            }
        }