public List<ProdResult> ReturnProduct(int? catagoryId)
 {
     var _db = new WebFormsDemo.Models.ProductContext();
     List<ProdResult> product = null;
     IQueryable<Product> query = _db.Products;
     if (catagoryId.HasValue && catagoryId > 0)
     {
         query = query.Where(p => p.CategoryID == catagoryId);
     }
     if (query.Count()>0)
     {
         IEnumerable<Product> penum = query.AsEnumerable<Product>();
         product = new List<ProdResult>();
         for (int i = 0; i < penum.Count(); i++)
         {
             ProdResult prod = new ProdResult();
             prod.ProductName = penum.ElementAt(i).ProductName.Trim();
             prod.Description = penum.ElementAt(i).Description.Trim();
             prod.ImagePath = penum.ElementAt(i).ImagePath.Trim();
             prod.UnitPrice = penum.ElementAt(i).UnitPrice.ToString().Trim();
             product.Add(prod);
             prod = null;
         }
     }
     return product;
 }
 public IQueryable<Product> GetProducts([QueryString("id")] int? categoryId)
 {
     var _db = new WebFormsDemo.Models.ProductContext();
     IQueryable<Product> query = _db.Products;
     if (categoryId.HasValue && categoryId > 0)
     {
         query = query.Where(p => p.CategoryID == categoryId);
     }
     return query;
 }
 public IQueryable<Product> GetProduct([QueryString("productID")] int? productid)
 {
     var _db = new WebFormsDemo.Models.ProductContext();
     IQueryable<Product> query = _db.Products;
     if (productid.HasValue && productid > 0)
     {
         query = query.Where(p => p.ProductID == productid);
     }
     else
     {
         query = null;
     }
     return query;
 }
Esempio n. 4
0
 public IQueryable<Catagory> GetCategories()
 {
     var _db = new WebFormsDemo.Models.ProductContext();
     IQueryable<Catagory> query = _db.Catagories;
     return query;
 }