Ejemplo n.º 1
0
 public void UpdateShoppingCartDatabase(String cartId, ShoppingCartUpdates[] CartItemUpdates)
 {
     using (var db = new ShopGameOnline.Models.GameContext())
     {
         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.Game.GameID == CartItemUpdates[i].GameId)
                     {
                         if (CartItemUpdates[i].PurchaseQuantity < 1 ||
                             CartItemUpdates[i].RemoveItem == true)
                         {
                             RemoveItem(cartId, cartItem.GameId);
                         }
                         else
                         {
                             UpdateItem(cartId, cartItem.GameId,
                                        CartItemUpdates[i].PurchaseQuantity);
                         }
                     }
                 }
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Database - " + exp.Message.ToString(), exp);
         }
     }
 }
Ejemplo n.º 2
0
        public IQueryable <Category> GetCategories()
        {
            var _db = new ShopGameOnline.Models.GameContext();
            IQueryable <Category> query = _db.Categories;

            return(query);
        }
Ejemplo n.º 3
0
        public IQueryable <Game> GetGames([QueryString("id")] int?categoryId)
        {
            var _db = new ShopGameOnline.Models.GameContext();
            IQueryable <Game> query = _db.Games;

            if (categoryId.HasValue && categoryId > 0)
            {
                query = query.Where(p => p.CategoryID == categoryId);
            }
            return(query);
        }
Ejemplo n.º 4
0
        public IQueryable <Game> GetDetails([QueryString("gameID")] int?gameId)
        {
            var _db = new ShopGameOnline.Models.GameContext();
            IQueryable <Game> query = _db.Games;

            if (gameId.HasValue && gameId > 0)
            {
                query = query.Where(p => p.GameID == gameId);
            }
            else
            {
                query = null;
            }
            return(query);
        }
Ejemplo n.º 5
0
 public void UpdateItem(string updateCartID, int updateGameID, int quantity)
 {
     using (var _db = new ShopGameOnline.Models.GameContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems where c.CartId == updateCartID && c.Game.GameID == updateGameID 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);
         }
     }
 }
Ejemplo n.º 6
0
 public void RemoveItem(string removeCartID, int removeGameID)
 {
     using (var _db = new ShopGameOnline.Models.GameContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems where c.CartId == removeCartID && c.Game.GameID == removeGameID 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);
         }
     }
 }