コード例 #1
0
 public void UpdateShoppingCartDatabase(String cartId, ShoppingCartUpdates[] CartItemUpdates)
 {
     using (var db = new BASITraining.Models.p_context())
     {
         try
         {
             int             CartItemCount = CartItemUpdates.Count();
             List <cartitem> myCart        = GetCartItems();
             foreach (var cartItem in myCart)
             {
                 // Iterate through all rows within shopping cart list
                 for (int i = 0; i < CartItemCount; i++)
                 {
                     if (cartItem.Product.ProductID == CartItemUpdates[i].ProductId)
                     {
                         if (CartItemUpdates[i].RemoveItem == true)
                         {
                             RemoveItem(cartId, cartItem.ProductId);
                         }
                         else
                         {
                             UpdateItem(cartId, cartItem.ProductId);
                         }
                     }
                 }
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Database - " + exp.Message.ToString(), exp);
         }
     }
 }
コード例 #2
0
        public IQueryable <category> GetCategories()
        {
            var _db = new BASITraining.Models.p_context();
            IQueryable <category> query = _db.Categories;

            return(query);
        }
コード例 #3
0
        public IQueryable <product> GetProducts([QueryString("id")] int?CategoryID)
        {
            var _db = new BASITraining.Models.p_context();
            IQueryable <product> query = _db.Products;

            if (CategoryID.HasValue && CategoryID > 0)
            {
                query = query.Where(p => p.CategoryID == CategoryID);
            }
            return(query);
        }
コード例 #4
0
 public void DeleteShoppingCartDatabase(String cartId)
 {
     using (var db = new BASITraining.Models.p_context())
     {
         try
         {
             DeleteItem(cartId);
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Database - " + exp.Message.ToString(), exp);
         }
     }
 }
コード例 #5
0
        //This code shows the GetProducts method which is referenced by the ItemType property of the ListView control
        //in the product_list.aspx page
        public IQueryable <product> GetProduct([QueryString("productID")] int?productId)
        {
            var _db = new BASITraining.Models.p_context();
            IQueryable <product> query = _db.Products;

            if (productId.HasValue && productId > 0)
            {
                query = query.Where(p => p.ProductID == productId);
            }
            else
            {
                query = null;
            }
            return(query);
        }
コード例 #6
0
 public void UpdateItem(string updateCartID, int updateProductID)
 {
     using (var _db = new BASITraining.Models.p_context())
     {
         try
         {
             var myItem = (from c in _db.coursecartitems where c.CartId == updateCartID && c.Product.ProductID == updateProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
コード例 #7
0
 public void DeleteItem(string removeCartID)
 {
     using (var _db = new BASITraining.Models.p_context())
     {
         try
         {
             var myItem = (from c in _db.coursecartitems where c.CartId == removeCartID select c).FirstOrDefault();
             if (myItem != null)
             {
                 // Remove Item.
                 _db.coursecartitems.Remove(myItem);
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }