Пример #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
 //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>());
     }
 }
Пример #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (BookshopModel b = new BookshopModel())
                {
                    if (Session["query"] != null)
                    {
                        TextBox1.Text = Session["query"].ToString();
                        SearchByTitle();
                        Session["query"] = null;
                    }
                    else
                    {
                        GenerateGrid();
                    }

                    var q = b.Categories.Select(x => x.Name).ToList();
                    foreach (Category x in b.Categories)
                    {
                        DropDownList1.Items.Add(x.Name);
                    }
                }
            }

            // Fix for ASPNet Grid views, to work with Bootstrap Tables
            //GridView1.UseAccessibleHeader = true;
            //GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
        }
Пример #4
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();
            }
        }
Пример #5
0
 public static List <OrderDetail> SortOrderID()
 {
     using (BookshopModel entities = new BookshopModel())
     {
         return(entities.OrderDetails.OrderByDescending(x => x.OrderID).ToList <OrderDetail>());
     }
 }
Пример #6
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            string param_isbn = Request.QueryString["isbn"];

            if (param_isbn != null)
            {
                string isbn = param_isbn;
                //Button lb = (Button)sender;
                //HiddenField hd = (HiddenField)lb.FindControl("HiddenFieldID");
                //int id = Convert.ToInt32(hd.Value);
                BookshopModel b = new BookshopModel();
                if (Session["cart"] == null)
                {
                    List <Item> cart = new List <Item>();
                    cart.Add(new Item(b.Books.Where(x => x.ISBN == isbn).First(), 1));
                    Session["cart"] = cart;
                }
                else
                {
                    List <Item> cart  = (List <Item>)Session["cart"];
                    int         index = isExisting(isbn);
                    if (index == -1)
                    {
                        cart.Add(new Item(b.Books.Where(x => x.ISBN == isbn).First(), 1));
                    }
                    else
                    {
                        cart[index].Quantity++;
                        Session["cart"] = cart;
                    }
                }
            }
        }
Пример #7
0
        // Updates page given a book
        protected void UpdatePage()
        {
            // Grab the attributes from the URL
            string param_isbn = Request.QueryString["isbn"];

            if (param_isbn != null)
            {
                string isbn = param_isbn;

                // Populate the page with information about the book
                using (BookshopModel entities = new BookshopModel())
                {
                    // Get Book
                    Book b = entities.Books.Where(x => x.ISBN == isbn).First();

                    // Update Elements
                    Image1.ImageUrl    = "~/Reference/Images/" + b.ISBN + ".jpg";
                    title.InnerText    = b.Title;
                    author.InnerText   = b.Author;
                    synopsis.InnerText = b.Synopsis;
                    price.InnerText    = "$" + b.Price;

                    details_author.InnerText = b.Author;
                    details_name.InnerText   = b.Title;
                    details_isbn.InnerText   = b.ISBN;
                }
            }
        }
Пример #8
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();
     }
 }
Пример #9
0
        //For CheckOut Page

        public static int GetLastOrderID()
        {
            using (BookshopModel entities = new BookshopModel())
            {
                var         q = SortOrderID();
                OrderDetail b = q.First();
                return(b.OrderID);
            }
        }
Пример #10
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();
     }
 }
Пример #11
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();
         }
     }
 }
Пример #12
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();
     }
 }
Пример #13
0
        protected void Button1_Click1(object sender, EventArgs e)
        {
            Button        lb = (Button)sender;
            HiddenField   hd = (HiddenField)lb.FindControl("HiddenFieldID");
            int           id = Convert.ToInt32(hd.Value);
            BookshopModel b  = new BookshopModel();

            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    if (Session["cart"] == null)
                    {
                        List <Item> cart = new List <Item>();
                        cart.Add(new Item(b.Books.Where(x => x.BookID == id).First(), 1));
                        Session["cart"] = cart;
                    }
                    else
                    {
                        List <Item> cart  = (List <Item>)Session["cart"];
                        int         index = isExisting(id);
                        if (index == -1)
                        {
                            cart.Add(new Item(b.Books.Where(x => x.BookID == id).First(), 1));
                        }
                        else
                        {
                            cart[index].Quantity++;
                            Session["cart"] = cart;
                        }
                    }
                    MsgBox("Item added to cart");
                    ts.Complete();
                }
            }
            catch (System.Transactions.TransactionException ex)
            {
                MsgBox(ex.ToString());
            }
            catch
            {
                MsgBox("ERROR: Item not added");
            }
        }
Пример #14
0
 protected void GenerateGrid()
 {
     Label1.Visible = false;
     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();
         }
     }
 }
Пример #15
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();
            }
        }
Пример #16
0
        protected void SearchByTitle()
        {
            using (BookshopModel ctx = new BookshopModel())
            {
                var q = ctx.Books.Where(x => x.Title.Contains(TextBox1.Text));
                if (q != null)
                {
                    GridView1.DataSource = q.ToList <Book>();
                    GridView1.DataBind();
                    if (GridView1.Rows.Count == 0)
                    {
                        Label1.Visible = true;
                    }
                    else
                    {
                        Label1.Visible = false;
                    }
                }

                DropDownList1.SelectedIndex = 0;
            }
        }
Пример #17
0
        /*scribbly here*/
        //public static void Current_TransactionCompleted(object sender, TransactionEventArgs e)
        //{
        //    if (e.Transaction.TransactionInformation.Status == TransactionStatus.Commited)
        //    {
        //        //session[“OrderID”] = LastOrderID;
        //    }
        //    else if (e.Transaction.TransactionInformation.Status == TransactionStatus.Aborted)
        //    {

        //    }
        //}

        //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>()); }
        }
Пример #18
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>()); }
 }
Пример #19
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>()); }
 }
Пример #20
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>()); }
 }
Пример #21
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>()); }
 }