Esempio n. 1
0
 public void UpdateShoppingCartDatabase(String cartId, ShoppingCartUpdates[] CartItemUpdates)
 {
     using (var db = new scifiBookStore.BLL.Model.ProductContext())
     {
         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].PurchaseQuantity < 1 || CartItemUpdates[i].RemoveItem == true)
                         {
                             RemoveItem(cartId, cartItem.ProductId);
                         }
                         else
                         {
                             UpdateItem(cartId, cartItem.ProductId, CartItemUpdates[i].PurchaseQuantity);
                         }
                     }
                 }
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Database - " + exp.Message.ToString(), exp);
         }
     }
 }
Esempio n. 2
0
 public void UpdateItem(string updateCartID, int updateProductID, int quantity)
 {
     //            using (webformsstorefrontEntities db = new webformsstorefrontEntities())
     using (var db = new scifiBookStore.BLL.Model.ProductContext())
     {
         try
         {
             var myItem = (from c in db.ShoppingCartItems where c.CartId == updateCartID && c.Product.productID == updateProductID 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);
         }
     }
 }
Esempio n. 3
0
 public void RemoveItem(string removeCartID, int removeProductID)
 {
     using (var db = new scifiBookStore.BLL.Model.ProductContext())
     {
         try
         {
             var myItem = (from c in db.ShoppingCartItems where c.CartId == removeCartID && c.Product.productID == removeProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 // db.DeleteObject(myItem);
                 db.ShoppingCartItems.Remove(myItem);
                 db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
Esempio n. 4
0
        public IQueryable <Product> GetProducts(
            [QueryString("id")] int?categoryId,
            [RouteData] string Name)
        {
            var _db = new scifiBookStore.BLL.Model.ProductContext();
            IQueryable <Product> query = _db.Products;

            if (categoryId.HasValue && categoryId > 0)
            {
                query = query.Where(p => p.CategoryID == categoryId);
            }

            if (!String.IsNullOrEmpty(Name))
            {
                query = query.Where(p =>
                                    String.Compare(p.Category.Name,
                                                   Name) == 0);
            }
            return(query);
        }
Esempio n. 5
0
        public IQueryable <Product> GetProduct(
            [QueryString("ProductID")] int?productId,
            [RouteData] string productName)
        {
            var _db = new scifiBookStore.BLL.Model.ProductContext();
            IQueryable <Product> query = _db.Products;

            if (productId.HasValue && productId > 0)
            {
                query = query.Where(p => p.productID == productId);
            }
            else if (!String.IsNullOrEmpty(productName))
            {
                query = query.Where(p =>
                                    String.Compare(p.Name, productName) == 0);
            }
            else
            {
                query = null;
            }
            return(query);
        }
Esempio n. 6
0
        public IQueryable <StoreCategory> GetCategories()
        {
            var db = new scifiBookStore.BLL.Model.ProductContext();

            return(db.Categories);
        }