protected void RemoveCategoryButton_Click(object sender, EventArgs e)
        {
            using (var _db = new CafeDroid_P3.Models.ProductContext())
            {
                int categoryId    = Convert.ToInt16(DropDownRemoveCategory.SelectedValue);
                var myProductItem = (from p in _db.Products where p.CategoryID == categoryId select p).FirstOrDefault();
                if (myProductItem == null)
                {
                    var myItem = (from c in _db.Categories where c.CategoryID == categoryId select c).FirstOrDefault();
                    if (myItem != null)
                    {
                        _db.Categories.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 + "?CategoryAction=remove");
                    }
                    else
                    {
                        LabelRemoveStatus.Text = "Unable to locate category.";
                    }
                }
                else
                {
                    LabelRemoveStatus.Text = "There are products under this category.";
                }
            }
        }
Beispiel #2
0
 public void UpdateItem(string updateCartID, int updateProductID, int quantity)
 {
     using (var _db = new CafeDroid_P3.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);
         }
     }
 }
Beispiel #3
0
 public void RemoveItem(string removeCartID, int removeProductID)
 {
     using (var _db = new CafeDroid_P3.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);
         }
     }
 }