public IQueryable <TheLoaiTruyen> GetCategories()
        {
            var _db = new ShopTruyenTranh.Models.DinhNghiaTruyen();
            IQueryable <TheLoaiTruyen> query = _db.TheLoais;

            return(query);
        }
Пример #2
0
        public IQueryable <TruyenTranh> GetBooks([QueryString("id")] int?categoryId)
        {
            var _db = new ShopTruyenTranh.Models.DinhNghiaTruyen();
            IQueryable <TruyenTranh> query = _db.TruyenTranhs;

            if (categoryId.HasValue && categoryId > 0)
            {
                query = query.Where(p => p.MaTL == categoryId);
            }
            return(query);
        }
Пример #3
0
        public IQueryable <TruyenTranh> GetDetails([QueryString("bookID")] int?bookId)
        {
            var _db = new ShopTruyenTranh.Models.DinhNghiaTruyen();
            IQueryable <TruyenTranh> query = _db.TruyenTranhs;

            if (bookId.HasValue && bookId > 0)
            {
                query = query.Where(p => p.MaTruyen == bookId);
            }
            else
            {
                query = null;
            }
            return(query);
        }
 public void UpdateItem(string updateCartID, int updateBookID, int
                        quantity)
 {
     using (var _db = new ShopTruyenTranh.Models.DinhNghiaTruyen())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems
                           where c.CartId == updateCartID && c.TruyenTranh.MaTruyen == 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);
         }
     }
 }
 public void UpdateShoppingCartDatabase(String cartId, ShoppingCartUpdates[]
                                        CartItemUpdates)
 {
     using (var db = new ShopTruyenTranh.Models.DinhNghiaTruyen())
     {
         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.TruyenTranh.MaTruyen == CartItemUpdates[i].MaTruyen)
                     {
                         if (CartItemUpdates[i].PurchaseQuantity < 1 ||
                             CartItemUpdates[i].RemoveItem == true)
                         {
                             RemoveItem(cartId, cartItem.MaTruyen);
                         }
                         else
                         {
                             UpdateItem(cartId, cartItem.MaTruyen,
                                        CartItemUpdates[i].PurchaseQuantity);
                         }
                     }
                 }
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Database - " +
                                 exp.Message.ToString(), exp);
         }
     }
 }
 public void RemoveItem(string removeCartID, int removeBookID)
 {
     using (var _db = new ShopTruyenTranh.Models.DinhNghiaTruyen())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems
                           where c.CartId == removeCartID && c.TruyenTranh.MaTruyen ==
                           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);
         }
     }
 }