public IQueryable <Product> GetAllProducts([Control("productsDropDownList")] string productBrand = "") { List <Product> allProductsList = new List <Product>(); WbsDAL wbs = new WbsDAL(); wbs.OpenConnection($"Data Source=(local);Initial Catalog=WebbShop;Integrated Security=True"); allProductsList = wbs.GetProducts(); //Same solution as the one below //if (string.IsNullOrEmpty(productBrand)) //{ // return wbs.GetProducts().AsQueryable(); //} //else //{ // return wbs.GetProducts().Where(x => x.ProductBrand == productBrand).AsQueryable(); //} return(string.IsNullOrEmpty(productBrand) ? wbs.GetProducts().AsQueryable() : wbs.GetProducts().Where(x => x.ProductBrand == productBrand).AsQueryable()); }
public IEnumerable <Product> GetBrands() { IEnumerable <Product> productList = new List <Product>(); WbsDAL invDAL = new WbsDAL(); invDAL.OpenConnection($"Data Source=(local); Integrated Security = true; Initial Catalog=WebbShop"); productList = invDAL.GetProducts(); productList.Select(x => new { x.ProductBrand }).Distinct(); return(productList); }