示例#1
0
 public void UpdateShoppingCartDatabase(String cartId, ShoppingCartUpdates[] CartItemUpdates)
 {
     using (var db = new RCShopOnline.Models.RCContext())
     {
         try
         {
             int             CartItemCount = CartItemUpdates.Count();
             List <CartItem> myCart        = GetCartItems();
             foreach (var cartItem in myCart)
             {
                 for (int i = 0; i < CartItemCount; i++)
                 {
                     if (cartItem.RC.RCID == CartItemUpdates[i].RCID)
                     {
                         if (CartItemUpdates[i].PurchaseQuantity < 1 ||
                             CartItemUpdates[i].RemoveItem == true)
                         {
                             RemoveItem(cartId, cartItem.RCID);
                         }
                         else
                         {
                             UpdateItem(cartId, cartItem.RCID,
                                        CartItemUpdates[i].PurchaseQuantity);
                         }
                     }
                 }
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Database - " +
                                 exp.Message.ToString(), exp);
         }
     }
 }
        public IQueryable <Category> GetCategories()
        {
            var _db = new RCShopOnline.Models.RCContext();
            IQueryable <Category> query = _db.Categories;

            return(query);
        }
        public IQueryable <RC> GetRCs([QueryString("id")] int?categoryId)
        {
            var             _db   = new RCShopOnline.Models.RCContext();
            IQueryable <RC> query = _db.RCs;

            if (categoryId.HasValue && categoryId > 0)
            {
                query = query.Where(p => p.CategoryID == categoryId);
            }
            return(query);
        }
示例#4
0
        public IQueryable <RC> GetDetails([QueryString("RCID")] int?RCId)
        {
            var             _db   = new RCShopOnline.Models.RCContext();
            IQueryable <RC> query = _db.RCs;

            if (RCId.HasValue && RCId > 0)
            {
                query = query.Where(p => p.RCID == RCId);
            }
            else
            {
                query = null;
            }
            return(query);
        }
示例#5
0
 public void UpdateItem(string updateCartID, int updateRCID, int quantity)
 {
     using (var _db = new RCShopOnline.Models.RCContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems
                           where c.CartId == updateCartID && c.RC.RCID == updateRCID 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);
         }
     }
 }
示例#6
0
 public void RemoveItem(string removeCartID, int removeRCID)
 {
     using (var _db = new RCShopOnline.Models.RCContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems
                           where c.CartId == removeCartID && c.RC.RCID == removeRCID
                           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);
         }
     }
 }