Ejemplo n.º 1
0
        public IQueryable GetProducts()
        {
            var        _db   = new WingtipToys.Data.ProductContext();
            IQueryable query = _db.Products;

            return(query);
        }
Ejemplo n.º 2
0
        public IQueryable <Product> GetProducts(
            [QueryString("id")] int?categoryId,
            [RouteData] string categoryName)
        {
            var _db = new WingtipToys.Data.ProductContext();
            IQueryable <Product> query = _db.Products;

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

            if (!String.IsNullOrEmpty(categoryName))
            {
                query = query.Where(p =>
                                    String.Compare(p.Category.CategoryName,
                                                   categoryName) == 0);
            }
            return(query);
        }
Ejemplo n.º 3
0
        protected void RemoveProductButton_Click(object sender, EventArgs e)
        {
            using (var _db = new WingtipToys.Data.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.º 4
0
        public IQueryable <Product> GetProduct(
            [QueryString("ProductID")] int?productId,
            [RouteData] string productName)
        {
            var _db = new WingtipToys.Data.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.ProductName, productName) == 0);
            }
            else
            {
                query = null;
            }
            return(query);
        }