コード例 #1
0
 //For browse Page
 //To list all books
 public static List <Book> ListAllBooks()
 {
     using (BookshopModel entities = new BookshopModel())
     {
         return(entities.Books.ToList <Book>());
     }
 }
コード例 #2
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();
                }
                Transaction.Current.TransactionCompleted += new TransactionCompletedEventHandler(Current_TransactionCompleted);
                Ts.Complete();
            }
        }
コード例 #3
0
 //For browse Page
 //To sort Booklist by Price descending
 public static List <Book> SortBooksByPriceDesc()
 {
     using (BookshopModel entities = new BookshopModel())
     {
         return(entities.Books.OrderByDescending(x => x.Price).ToList <Book>());
     }
 }
コード例 #4
0
 public static List <OrderDetail> SortOrderID()
 {
     using (BookshopModel entities = new BookshopModel())
     {
         return(entities.OrderDetails.OrderByDescending(x => x.OrderID).ToList <OrderDetail>());
     }
 }
コード例 #5
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     using (BookshopModel ctx = new BookshopModel())
     {
         var q = ctx.Books.Where(x => x.Title.Contains(TextBox1.Text));
         GridView1.DataSource = q.ToList <Book>();
         GridView1.DataBind();
     }
 }
コード例 #6
0
        //For CheckOut Page

        public static int GetLastOrderID()
        {
            using (BookshopModel entities = new BookshopModel())
            {
                var         q = SortOrderID();
                OrderDetail b = q.First();
                return(b.OrderID);
            }
        }
コード例 #7
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         using (BookshopModel b = new BookshopModel())
         {
             GridView1.DataSource = b.Books.ToList <Book>();
             GridView1.DataBind();
             var q = b.Categories.Select(x => x.Name).ToList();
             foreach (Category x in b.Categories)
             {
                 DropDownList1.Items.Add(x.Name);
             }
         }
     }
 }
コード例 #8
0
 protected void GenerateGrid()
 {
     using (BookshopModel b = new BookshopModel())
     {
         if (DropDownList1.SelectedValue != "0")
         {
             string category = DropDownList1.SelectedItem.Text.ToString();
             var    q        = from x in b.Books where x.Category.Name == DropDownList1.SelectedValue.ToString() select x;
             GridView1.DataSource = q.ToList <Book>();
             GridView1.DataBind();
         }
         else
         {
             GridView1.DataSource = b.Books.ToList <Book>();
             GridView1.DataBind();
         }
     }
 }
コード例 #9
0
 // For View Details Page
 //To View Details (use selected book ID as input argument)
 public static List <Book> ListBookDetails(int BID)
 {
     using (BookshopModel entities = new BookshopModel())
     { return(entities.Books.Where(p => p.BookID == BID).ToList <Book>()); }
 }
コード例 #10
0
 //For browse Page
 //To sort Booklist by title ascending
 public static List <Book> SortBooksByTitle()
 {
     using (BookshopModel entities = new BookshopModel())
     { return(entities.Books.OrderBy(x => x.Title).ToList <Book>()); }
 }
コード例 #11
0
 //For browse Page
 //To search/list by CategoryName (use dropdown selected index)
 public static List <Book> SearchByCategory(int CID)
 {
     using (BookshopModel entities = new BookshopModel())
     { return(entities.Books.Where(p => p.CategoryID == (CID + 1)).ToList <Book>()); }
 }
コード例 #12
0
 //For browse Page
 //To search/list by required Author
 public static List <Book> SearchByBookAuthor(string name)
 {
     using (BookshopModel entities = new BookshopModel())
     { return(entities.Books.Where(p => p.Author.Contains(name)).ToList <Book>()); }
 }
コード例 #13
0
        //To display Order details for Confirmation Page

        public static List <OrderDetail> DisplayOrder(int OID)
        {
            using (BookshopModel entities = new BookshopModel())
            { return(entities.OrderDetails.Where(p => p.OrderID == OID).ToList <OrderDetail>()); }
        }