public static List <Book> ListBook() { using (BookShop_EF2 entities = new BookShop_EF2()) { return(entities.Books.ToList <Book>()); } }
public List <Book> OrderByPrice() { using (BookShop_EF2 BookShop = new BookShop_EF2()) { return(BookShop.Books.OrderByDescending(x => x.Price).ToList()); } }
public static List <Book> ListOrdersBy(int id) { using (BookShop_EF2 entities = new BookShop_EF2()) { return(entities.Books.Where(p => p.CategoryId == id).ToList <Book>()); } }
public static List <User> ListUsersBy() { using (BookShop_EF2 entities = new BookShop_EF2()) { return(entities.Users.ToList <User>()); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { List <OrderDetail> gg = null; int userId2 = Int32.Parse(Request.QueryString["UserID"]); using (BookShop_EF2 entity = new BookShop_EF2()) { List <Order> od = entity.Orders.Where(p => p.UserId == userId2).ToList(); BookShop_EF2 bf = new BookShop_EF2(); var or = (from p in bf.OrderDetails join r in bf.Orders on p.OrderId equals r.OrderId where r.UserId == userId2 select new { OrderId = p.OrderId, OrderLine = p.OrderLine, BookId = p.BookId, Quantity = p.Quantity, LineAmount = p.LineAmount }).ToList(); GridView1.DataSource = or; GridView1.DataBind(); } } }
public static List <Discount> Discount() { using (BookShop_EF2 entities = new BookShop_EF2()) { return(entities.Discounts.ToList <Discount>()); } }
public List <Book> OrderByTitle() { using (BookShop_EF2 BookShop = new BookShop_EF2()) { return(BookShop.Books.OrderBy(x => x.Title).ToList()); } }
public List <Book> searchByAuthor(string keyword) { using (BookShop_EF2 BookShop = new BookShop_EF2()) { return(BookShop.Books.Where(x => x.Author.Contains(keyword)).ToList()); } }
public List <Book> selectAll() { using (BookShop_EF2 BookShop = new BookShop_EF2()) { return(BookShop.Books.ToList()); } }
public static List <Category> ListCat() { using (BookShop_EF2 entities = new BookShop_EF2()) { return(entities.Categories.ToList <Category>()); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["BookId"] != null && !IsPostBack) { int myBookId = Convert.ToInt32(Request.QueryString["BookId"]); using (BookShop_EF2 BookShop = new BookShop_EF2()) { Book myBook = new Book(); myBook = BookShop.Books.Where(x => x.BookId == myBookId).First(); ViewState["BookId"] = myBookId; shopController sc = new shopController(); string title = (string)Session["booktitle"]; //string title = ;//For testing purpose //Book b = sc.loadBook(title); /*Category c = sc.loadCategory(b);*///Mr. Derek, I feel it is not necessary to have a seperate table for category...... txtTitle.Text = myBook.Title; txtISBN.Text = myBook.ISBN; txtAuthor.Text = myBook.Author; txtCat.Text = myBook.Category.Genre; txtQuantity.Text = ""; txtPrice.Text = myBook.Price.ToString();//Original Price Image1.ImageUrl = "~/images/" + myBook.ISBN + ".jpg"; } } else if (Request.QueryString["BookId"] == null) { Response.Redirect("~/CataloguePage.aspx"); } }
public Category loadCategory(Book b) { using (BookShop_EF2 BookShop = new BookShop_EF2()) { Category c = BookShop.Categories.Where(x => x.CategoryId == b.CategoryId).First(); return(c); } }
public Book loadBook(string title) { using (BookShop_EF2 BookShop = new BookShop_EF2()) { Book b = BookShop.Books.Where(x => x.Title == title).First(); return(b); } }
public static void DeleteDis(int Disid) { using (BookShop_EF2 entities = new BookShop_EF2()) { Discount order = entities.Discounts.Where(p => p.DiscountId == Disid).First <Discount>(); entities.Discounts.Remove(order); entities.SaveChanges(); } }
private void BindGrid() { using (BookShop_EF2 ctx = new BookShop_EF2()) { var shoppingcart = ctx.ShoppingCarts.ToList(); GridView1.DataSource = shoppingcart; GridView1.DataBind(); } }
public static void DeleteBook(int Bookid) { using (BookShop_EF2 entities = new BookShop_EF2()) { Book order = entities.Books.Where(p => p.BookId == Bookid).First <Book>(); entities.Books.Remove(order); entities.SaveChanges(); } }
public static void DeleteUser(int userId) { using (BookShop_EF2 entities = new BookShop_EF2()) { User user = entities.Users.Where(p => p.UserId == userId).First <User>(); entities.Users.Remove(user); entities.SaveChanges(); } }
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { using (BookShop_EF2 ctx = new BookShop_EF2()) { int bookId = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0]); var id = ctx.Books.Where(x => x.BookId == bookId).FirstOrDefault(); ctx.Books.Remove(id); ctx.SaveChanges(); BindGrid(); } }
public static void UpdateDis(int Disid, string Promo, int rate) { using (BookShop_EF2 entities = new BookShop_EF2()) { Discount order = entities.Discounts.Where(p => p.DiscountId == Disid).First <Discount>(); order.DiscountId = Disid; order.PromoName = Promo; order.DiscountRate = rate; entities.SaveChanges(); } }
public static void RegistUser(string name, string password, string address) { using (BookShop_EF2 entities = new BookShop_EF2()) { User usr = new User { UserName = name, Password = password, Address = address, }; entities.Users.Add(usr); entities.SaveChanges(); } }
public static void UpdateBook(int bookid, string Title, string Author, string ISBN, decimal Price) { using (BookShop_EF2 entities = new BookShop_EF2()) { Book order = entities.Books.Where(p => p.BookId == bookid).First <Book>(); order.BookId = bookid; order.Title = Title; order.Author = Author; order.ISBN = ISBN; order.Price = Price; //order.CategoryId = Category; entities.SaveChanges(); } }
public static void AddDis(string Promo, int dis, DateTime st, DateTime et) { using (BookShop_EF2 entities = new BookShop_EF2()) { Discount cat = new Discount { PromoName = Promo, DiscountRate = dis, StartDate = st, EndDate = et, }; entities.Discounts.Add(cat); entities.SaveChanges(); } }
public List <Book> find4Book() { using (BookShop_EF2 BookShop = new BookShop_EF2()) { Book a = BookShop.Books.Find(1); Book b = BookShop.Books.Find(2); Book c = BookShop.Books.Find(3); Book d = BookShop.Books.Find(4); List <Book> book = new List <Book>(); book.Add(a); book.Add(b); book.Add(c); book.Add(d); return(book); } }
public static void AddBook(string title, string author, string isbn, int categoryID, decimal price, int stock) { using (BookShop_EF2 entities = new BookShop_EF2()) { Book cat = new Book { Title = title, Author = author, ISBN = isbn, CategoryId = categoryID, Price = price, Stock = stock, }; entities.Books.Add(cat); entities.SaveChanges(); } }
protected void btnAddToCart_Click(object sender, EventArgs e) { Session["BookTitle"] = txtTitle.Text; using (BookShop_EF2 BookShop = new BookShop_EF2()) { shopController sc = new shopController(); string title = (string)Session["booktitle"]; //string title = "The Hate U Give";//For testing purpose Book b = sc.loadBook(title); // For Luke's login part //if (Session["username"] == null) //{ // Response.Redirect("Login.aspx"); //} if (Session["cart"] != null) { CartList cl = (CartList)Session["cart"]; int id = b.BookId; decimal price = 0; price = b.Price; int quantity = Convert.ToInt32(txtQuantity.Text); cartController cc = new cartController(); cl = cc.addItem(cl, id, title, price, quantity); Session["cart"] = cl; } else { CartList cl = new CartList(); int id = b.BookId; decimal price = 0; price = b.Price; int quantity = Convert.ToInt32(txtQuantity.Text); cartController cc = new cartController(); cl = cc.addItem(cl, id, title, price, quantity); Session["cart"] = cl; } Response.Redirect("ViewCart.aspx"); } }
private void LoadByCategory() { if (DropDownList1.SelectedItem.ToString() == "Choose Category") { BindGrid(); } else { using (BookShop_EF2 entities = new BookShop_EF2()) { string Categoryname = DropDownList1.SelectedItem.ToString(); Category CatId = entities.Categories.Where(p => p.Genre == Categoryname).First <Category>(); GridView1.DataSource = BusinessLogic.ListOrdersBy(CatId.CategoryId); GridView1.DataBind(); } } }
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { using (BookShop_EF2 ctx = new BookShop_EF2()) { if (e.Row.RowType == DataControlRowType.DataRow) { ShoppingCart sc = (ShoppingCart)e.Row.DataItem; DropDownList ddl = (e.Row.FindControl("ddlCategory") as DropDownList); if (ddl != null) { ddl.DataSource = ctx.Users.ToList(); ddl.DataTextField = "Name"; ddl.DataValueField = "CategoryID"; ddl.DataBind(); } TextBox author = (e.Row.FindControl("tbxAuthor") as TextBox); } } }
public void minusStock(CartList cl) { using (BookShop_EF2 bookshop = new BookShop_EF2()) { List <Cart> cart = cl.getCl(); for (int i = 0; i < cart.Count; i++) { Cart c = cart[i]; Book b = bookshop.Books.Find(c.b.BookId); int bookstock = 1; bookstock = b.Stock - 1; b.Stock = bookstock; bookshop.SaveChanges(); } } }
protected void Login1_Click(object sender, EventArgs e) { //Session["name"] = name.Text; using (BookShop_EF2 ctx = new BookShop_EF2()) { User namecheck = ctx.Users.Where(p => p.UserName == name.Text).First <User>(); if (namecheck.Password == passowrd.Text) { if (name.Text == "admin") { Response.Redirect("home.aspx"); } else { Response.Redirect("ViewCart.aspx"); } } else { Response.Redirect("Login.aspx"); } } }