public IQueryable GetBooks()
        {
            var        _db   = new Baitayonline.Models.BookContext();
            IQueryable query = _db.Books;

            return(query);
        }
        public IQueryable <Category> GetCategories()
        {
            var _db = new Baitayonline.Models.BookContext();
            IQueryable <Category> query = _db.Categories;

            return(query);
        }
        public IQueryable <Book> GetBooks([QueryString("id")] int?categoryId)
        {
            var _db = new Baitayonline.Models.BookContext();
            IQueryable <Book> query = _db.Books;

            if (categoryId.HasValue && categoryId > 0)
            {
                query = query.Where(p => p.CategoryID == categoryId);
            }
            return(query);
        }
Exemple #4
0
        public IQueryable <Book> GetDetails([QueryString("productID")] int?bookId)
        {
            var _db = new Baitayonline.Models.BookContext();
            IQueryable <Book> query = _db.Books;

            if (bookId.HasValue && bookId > 0)
            {
                query = query.Where(p => p.BookID == bookId);
            }
            else
            {
                query = null;
            }
            return(query);
        }
Exemple #5
0
 public void UpdateShoppingCartDatabase(String cartId, ShoppingCartUpdates[]
                                        CartItemUpdates)
 {
     using (var db = new Baitayonline.Models.BookContext())
     {
         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.Book.BookID == CartItemUpdates[i].BookId)
                     {
                         if (CartItemUpdates[i].PurchaseQuantity < 1 ||
                             CartItemUpdates[i].RemoveItem == true)
                         {
                             RemoveItem(cartId, cartItem.BookId);
                         }
                         else
                         {
                             UpdateItem(cartId, cartItem.BookId,
                                        CartItemUpdates[i].PurchaseQuantity);
                         }
                     }
                 }
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Database - " +
                                 exp.Message.ToString(), exp);
         }
     }
 }
 protected void RemoveBookButton_Click(object sender, EventArgs e)
 {
     using (var _db = new Baitayonline.Models.BookContext())
     {
         int bookId = Convert.ToInt16(DropDownRemoveBook.SelectedValue);
         var myItem = (from c in _db.Books
                       where c.BookID == bookId
                       select
                       c).FirstOrDefault();
         if (myItem != null)
         {
             _db.Books.Remove(myItem);
             _db.SaveChanges();
             // Tải lại trang.
             string pageUrl = Request.Url.AbsoluteUri.Substring(0,
                                                                Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
             Response.Redirect(pageUrl + "?BookAction=remove");
         }
         else
         {
             LabelRemoveStatus.Text = "Unable to locate book.";
         }
     }
 }
Exemple #7
0
 public void UpdateItem(string updateCartID, int updateBookID, int
                        quantity)
 {
     using (var _db = new Baitayonline.Models.BookContext())
     {
         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);
         }
     }
 }
Exemple #8
0
 public void RemoveItem(string removeCartID, int removeBookID)
 {
     using (var _db = new Baitayonline.Models.BookContext())
     {
         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);
         }
     }
 }