Exemple #1
0
        public IQueryable <Hang> GetHangs()
        {
            var _db = new QH_COMPUTER.Models.TenDL();
            IQueryable <Hang> query = _db.Hangs;

            return(query);
        }
Exemple #2
0
        public IQueryable <LapTop> GetLapTops([QueryString("id")] int?hangId)
        {
            var _db = new QH_COMPUTER.Models.TenDL();
            IQueryable <LapTop> query = _db.LapTops;

            if (hangId.HasValue && hangId > 0)
            {
                query = query.Where(p => p.HangID == hangId);
            }
            return(query);
        }
Exemple #3
0
        public IQueryable <LapTop> GetDetails([QueryString("laptopID")] int?laptopId)
        {
            var _db = new QH_COMPUTER.Models.TenDL();
            IQueryable <LapTop> query = _db.LapTops;

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