//protected void Page_PreRender(object sender, EventArgs e) //{ // using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions()) // { // string cartStr = string.Format("Cart ({0})", // usersShoppingCart.GetCount()); // t5.InnerText = cartStr; // } //} public IQueryable <Category> GetCategories() { var _db = new BooksShopOnline.Models.SportContext(); IQueryable <Category> query = _db.SportCategories; return(query); }
public IQueryable <Sport> GetBooks([QueryString("id")] int?categoryId) { var _db = new BooksShopOnline.Models.SportContext(); IQueryable <Sport> query = _db.Sports; if (categoryId.HasValue && categoryId > 0) { query = query.Where(p => p.CategoryID == categoryId); } return(query); }
public IQueryable <Sport> GetDetails([QueryString("BookID")] int?bookId) { var _db = new BooksShopOnline.Models.SportContext(); IQueryable <Sport> query = _db.Sports; if (bookId.HasValue && bookId > 0) { query = query.Where(p => p.SportID == bookId); } else { query = null; } return(query); }
public void RemoveItem(string removeCartID, int removeBookID) { using (var _db = new BooksShopOnline.Models.SportContext()) { try { var myItem = (from c in _db.ShoppingCartItems where c.CartId == removeCartID && c.Book.BookID == removeBookID select c).FirstOrDefault(); if (myItem != null) { // Xóa _db.ShoppingCartItems.Remove(myItem); _db.SaveChanges(); } } catch (Exception exp) { throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp); } } }
public void UpdateShoppingCartDatabase(String cartId, ShoppingCartUpdates[] CartItemUpdates) { using (var db = new BooksShopOnline.Models.SportContext()) { try { int CartItemCount = CartItemUpdates.Count(); List <CartItem> myCart = GetCartItems(); foreach (var cartItem in myCart) { // Lặp qua các hàng trong giỏ hàng for (int i = 0; i < CartItemCount; i++) { if (cartItem.Sport.SportID == CartItemUpdates[i].SportId) { if (CartItemUpdates[i].PurchaseQuantity < 1 || CartItemUpdates[i].RemoveItem == true) { RemoveItem(cartId, cartItem.SportId); } else { UpdateItem(cartId, cartItem.SportId, CartItemUpdates[i].PurchaseQuantity); } } } } } catch (Exception exp) { throw new Exception("ERROR: Unable to Update Cart Database - " + exp.Message.ToString(), exp); } } }
public void UpdateItem(string updateCartID, int updateBookID, int quantity) { using (var _db = new BooksShopOnline.Models.SportContext()) { try { var myItem = (from c in _db.ShoppingCartItems where c.CartId == updateCartID && c.Book.BookID == updateBookID select c).FirstOrDefault(); if (myItem != null) { myItem.Quantity = quantity; _db.SaveChanges(); } } catch (Exception exp) { throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp); } } }