public bool ChangeStock(Cart c) { BookshopEntities bs = new BookshopEntities(); Book temp; try { string isbn = c.ISBN; temp = bs.Book.Where(x => x.ISBN == isbn).First(); } catch { return(false); } if (temp.Stock > 0) { temp.Stock -= 1; } else { return(false); } c.Status = "Removed"; bs.SaveChanges(); return(true); }
//Create a new class to show items details in cart public static List <CartItem> ShowCartItem(string user) { List <CartItem> result = new List <CartItem>(); using (BookshopEntities entities = new BookshopEntities()) { var q = from x in entities.Cart join y in entities.Book on x.ISBN equals y.ISBN where x.Status == "Unpaid" && x.Username == user select new { x.Title, y.Author, x.ISBN, y.Price, y.Discount, x.Quantity, x.Username }; foreach (var item in q) { CartItem ci = new CartItem(); ci.Username = item.Username; ci.Title = item.Title; ci.Author = item.Author; ci.ISBN = item.ISBN; ci.DiscountPrice = decimal.Round((Decimal)(item.Price * (1 - (Decimal)(item.Discount) / 100)), 2); ci.Quantity = item.Quantity; result.Add(ci); } } return(result); }
protected void Page_Load(object sender, EventArgs e) { user = Context.User.Identity.GetUserName(); var q = from x in new BusinessLogic().GetCartItems(user) select new { x.Title, x.ISBN, x.Price, x.Quantity }; GridView1.DataSource = q.ToList(); GridView1.DataBind(); Label_TotalPrice.Text = string.Format("Total Price is S$ {0}", new BusinessLogic().TotalPrice(user).ToString()); using (BookshopEntities context = new BookshopEntities()) { var cart = context.Cart.Where(x => x.Status == "Unpaid").ToList(); cart.ForEach(s => s.Status = "Paid"); context.SaveChanges(); } }
public int CountCart(string username) { int result = 0; BookshopEntities bs = new BookshopEntities(); try { List <Cart> ls_c = bs.Cart.Where(x => x.Username == username && x.Status == "Unpaid").ToList(); foreach (Cart c in ls_c) { result += c.Quantity; } } catch { result = 0; } return(result); }
protected void Page_Load(object sender, EventArgs e) { BookshopEntities m = new BookshopEntities(); var qry = from x in m.Book select x; List <Book> cLst = qry.ToList <Book>(); Repeater1.DataSource = BusinessLogic.ShowBySearch("Category", "Finance"); Repeater1.DataBind(); foreach (RepeaterItem q in Repeater1.Items) { string isbn = (q.FindControl("Label4") as Label).Text.ToString(); if ((new BusinessLogic()).ShowOriginalPrice(isbn)) { (q.FindControl("Label6") as Label).Visible = true; } else { (q.FindControl("Label6") as Label).Visible = false; } } }
//Create a new class to show detailed search results public static List <SelectedBooks> ShowBySearch(string catalogue, string text) { List <SelectedBooks> result = new List <SelectedBooks>(); using (BookshopEntities entities = new BookshopEntities()) { switch (catalogue) { case "Full Catalogue": var fc = from x in entities.Book join y in entities.Category on x.CategoryID equals y.CategoryID where x.Title.Contains(text) || x.Author.Contains(text) || y.Name.Contains(text) || x.ISBN.Contains(text) select new { x.Title, x.Author, x.ISBN, x.Stock, CategoryName = y.Name, x.Price, x.Discount }; foreach (var item in fc) { SelectedBooks sb = new SelectedBooks(); sb.Title = item.Title; sb.Author = item.Author; sb.ISBN = item.ISBN; sb.Stock = item.Stock; sb.CategoryName = item.CategoryName; sb.Price = item.Price; sb.DiscountPrice = decimal.Round((Decimal)(item.Price * (1 - (Decimal)(item.Discount) / 100)), 2); sb.ShowOriginalPrice = (item.Discount != 0); result.Add(sb); } break; case "Book Title": var bt = from x in entities.Book join y in entities.Category on x.CategoryID equals y.CategoryID where x.Title.Contains(text) select new { x.Title, x.Author, x.ISBN, x.Stock, CategoryName = y.Name, x.Price, x.Discount }; foreach (var item in bt) { SelectedBooks sb = new SelectedBooks(); sb.Title = item.Title; sb.Author = item.Author; sb.ISBN = item.ISBN; sb.Stock = item.Stock; sb.CategoryName = item.CategoryName; sb.Price = item.Price; sb.DiscountPrice = decimal.Round((Decimal)(item.Price * (1 - (Decimal)(item.Discount) / 100)), 2); result.Add(sb); } break; case "Author": var a = from x in entities.Book join y in entities.Category on x.CategoryID equals y.CategoryID where x.Author.Contains(text) select new { x.Title, x.Author, x.ISBN, x.Stock, CategoryName = y.Name, x.Price, x.Discount }; foreach (var item in a) { SelectedBooks sb = new SelectedBooks(); sb.Title = item.Title; sb.Author = item.Author; sb.ISBN = item.ISBN; sb.Stock = item.Stock; sb.CategoryName = item.CategoryName; sb.Price = item.Price; sb.DiscountPrice = decimal.Round((Decimal)(item.Price * (1 - (Decimal)(item.Discount) / 100)), 2); result.Add(sb); } break; case "Category": var c = from x in entities.Book join y in entities.Category on x.CategoryID equals y.CategoryID where y.Name.Contains(text) select new { x.Title, x.Author, x.ISBN, x.Stock, CategoryName = y.Name, x.Price, x.Discount }; foreach (var item in c) { SelectedBooks sb = new SelectedBooks(); sb.Title = item.Title; sb.Author = item.Author; sb.ISBN = item.ISBN; sb.Stock = item.Stock; sb.CategoryName = item.CategoryName; sb.Price = item.Price; sb.DiscountPrice = decimal.Round((Decimal)(item.Price * (1 - (Decimal)(item.Discount) / 100)), 2); result.Add(sb); } break; case "ISBN": var isbn = from x in entities.Book join y in entities.Category on x.CategoryID equals y.CategoryID where x.ISBN.Contains(text) select new { x.Title, x.Author, x.ISBN, x.Stock, CategoryName = y.Name, x.Price, x.Discount }; foreach (var item in isbn) { SelectedBooks sb = new SelectedBooks(); sb.Title = item.Title; sb.Author = item.Author; sb.ISBN = item.ISBN; sb.Stock = item.Stock; sb.CategoryName = item.CategoryName; sb.Price = item.Price; sb.DiscountPrice = decimal.Round((Decimal)(item.Price * (1 - (Decimal)(item.Discount) / 100)), 2); result.Add(sb); } break; } return(result); } }