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(); } }
//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(); } }
//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(); } } }
//Toaddcategory public static void SaveCategory(string category) { using (BookshopModel entities = new BookshopModel()) { Category c = new Category() { Name = category, }; entities.Categories.Add(c); entities.SaveChanges(); } }
//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(); } }
//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(); } }