Пример #1
0
        public IQueryable GetProducts()
        {
            var        _db   = new ECommerceWebFrom.Models.ProductContext();
            IQueryable query = _db.Products;

            return(query);
        }
Пример #2
0
        protected void RemoveProductButton_Click(object sender, EventArgs e)
        {
            using (var _db = new ECommerceWebFrom.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.";
                }
            }
        }