Ejemplo n.º 1
0
 public void UpdateShoppingCartDatabase(String cartId, ShoppingCartUpdates[] CartItemUpdates)
 {
     using (var db = new Wingtip_Toys.Models.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);
         }
     }
 }
Ejemplo n.º 2
0
        public IQueryable <Category> GetCategories()
        {
            var _db = new Wingtip_Toys.Models.ProductContext();
            IQueryable <Category> query = _db.Categories;

            return(query);
        }
Ejemplo n.º 3
0
        public IQueryable GetProducts()
        {
            var        _db   = new Wingtip_Toys.Models.ProductContext();
            IQueryable query = _db.Products;

            return(query);
        }
Ejemplo n.º 4
0
 public void Dispose()
 {
     if (_db != null)
     {
         _db.Dispose();
         _db = null;
     }
 }
Ejemplo n.º 5
0
 public IQueryable<Product> GetProducts([QueryString("id")] int? categoryId)
 {
     var _db = new Wingtip_Toys.Models.ProductContext();
     IQueryable<Product> query = _db.Products;
     if (categoryId.HasValue && categoryId > 0)
     {
         query = query.Where(p => p.CategoryID == categoryId);
     }
     return query;
 }
Ejemplo n.º 6
0
        public IQueryable <Product> GetProducts([QueryString("id")] int?categoryId)
        {
            var _db = new Wingtip_Toys.Models.ProductContext();
            IQueryable <Product> query = _db.Products;

            if (categoryId.HasValue && categoryId > 0)
            {
                query = query.Where(p => p.CategoryID == categoryId);
            }
            return(query);
        }
Ejemplo n.º 7
0
 public IQueryable<Product> GetProduct([QueryString("productID")] int? productId)
 {
     var _db = new Wingtip_Toys.Models.ProductContext();
     IQueryable<Product> query = _db.Products;
     if (productId.HasValue && productId > 0)
     {
         query = query.Where(p => p.ProductID == productId);
     }
     else
     {
         query = null;
     }
     return query;
 }
Ejemplo n.º 8
0
        public IQueryable <Product> GetProduct([QueryString("productID")] int?productId)
        {
            var _db = new Wingtip_Toys.Models.ProductContext();
            IQueryable <Product> query = _db.Products;

            if (productId.HasValue && productId > 0)
            {
                query = query.Where(p => p.ProductID == productId);
            }
            else
            {
                query = null;
            }
            return(query);
        }
Ejemplo n.º 9
0
 public void UpdateItem(string UpdateCartID, int updateProductID, int quantity)
 {
     using (var _db = new Wingtip_Toys.Models.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);
         }
     }
 }
Ejemplo n.º 10
0
 public void RemoveItem(string removeCartID, int removeProductID)
 {
     using (var _db = new Wingtip_Toys.Models.ProductContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems where c.CartID == removeCartID &&
                           c.Product.ProductID == removeProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 // Remove Item.
                 _db.ShoppingCartItems.Remove(myItem);
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
Ejemplo n.º 11
0
        protected void RemoveProductButton_Click(object sender, EventArgs e)
        {
            using (var _db = new Wingtip_Toys.Models.ProductContext())
            {
                int productId = Convert.ToInt16(DropDownRemoveProduct.SelectedValue);
                var myItem    = (from c in _db.Products where c.ProductID == productId select c).FirstOrDefault();
                if (myItem != null)
                {
                    _db.Products.Remove(myItem);
                    _db.SaveChanges();

                    // Reload the page.
                    string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
                    Response.Redirect(pageUrl + "?ProductAction=remove");
                }
                else
                {
                    LabelRemoveStatus.Text = "Unable to locate product.";
                }
            }
        }
Ejemplo n.º 12
0
 public IQueryable<Category> GetCategories()
 {
     var _db = new Wingtip_Toys.Models.ProductContext();
     IQueryable<Category> query = _db.Categories;
     return query;
 }
Ejemplo n.º 13
0
 public void UpdateShoppingCartDatabase(String cartId, ShoppingCartUpdates[] CartItemUpdates)
 {
     using (var db = new Wingtip_Toys.Models.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);
         }
     }
 }
Ejemplo n.º 14
0
 public void UpdateItem(string updateCartID, int updateProductID, int quantity)
 {
     using (var _db = new Wingtip_Toys.Models.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);
         }
     }
 }
Ejemplo n.º 15
0
 public void RemoveItem(string removeCartID, int removeProductID)
 {
     using (var _db = new Wingtip_Toys.Models.ProductContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems where c.CartId == removeCartID && c.Product.ProductID == removeProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 // Remove Item.
                 _db.ShoppingCartItems.Remove(myItem);
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }