public ProductListViewModel GetHomeModel(int categoryId) { var result = new ProductListViewModel(); var categories = _session .CreateCriteria<Category>() .Future<Category>(); result.Categories = categories; result.SelectedCategory = categories.SingleOrDefault(x => x.ID == categoryId); IEnumerable<Product> selectProducts = SelectProducts(categoryId); if (selectProducts.Count() > 0) { result.FeaturedProduct = selectProducts.First(); result.FeaturedProducts = selectProducts .Skip(1) .Take(3) .ToList(); } else { result.FeaturedProduct = new Product(); result.FeaturedProducts = new List<Product>(); } return result; }
public ProductListViewModel GetHomeModel() { var result = new ProductListViewModel(); //add the featured product result.FeaturedProducts = _repo.GetFeaturedProducts(); //categories result.Categories = _repo.GetCategories(); //organize them result.Categories.ToList().ForEach(x => x.SubCategories = result.Categories.Where(y => y.ParentID == x.ID).ToList()); return result; }
public ProductListViewModel GetCategoryModel(int categoryID) { var result = new ProductListViewModel(); //add the featured product result.FeaturedProducts = _repo.GetProducts(categoryID); //categories result.Categories = _repo.GetCategories(); result.SelectedCategory = _repo.GetCategories().SingleOrDefault(x => x.ID == categoryID); //organize them result.Categories.ToList().ForEach(x => x.SubCategories = result.Categories.Where(y => y.ParentID == x.ID).ToList()); return result; }
// IStoreRepository _repo; // public StoreService(IStoreRepository repo){ // _repo = repo; // } // public ProductListViewModel GetCategoryModel(int categoryID) { // var result = new ProductListViewModel(); // //add the featured product // result.FeaturedProducts = _repo.GetProducts(categoryID); // //categories // result.Categories = _repo.GetCategories(); // result.SelectedCategory = _repo.GetCategories().SingleOrDefault(x => x.ID == categoryID); // //organize them // result.Categories.ToList().ForEach(x => x.SubCategories = result.Categories.Where(y => y.ParentID == x.ID).ToList()); // return result; // } public ProductListViewModel GetHomeModel() { var result = new ProductListViewModel(); //add the featured product //categories result.Categories = _session .CreateCriteria<Category>() .Future<Category>(); var featuredProduct = _session .CreateCriteria<Product>() .SetFetchMode<Product>(x=>x.Descriptors,FetchMode.Join) .CreateCriteria<Product>(x=>x.Categories) .Add<Category>(x=>x.ID==33) .Future<Product>(); result.FeaturedProduct = featuredProduct.First(); result.FeaturedProducts = featuredProduct.Skip(1).Take(3).ToList(); return result; }
public ProductListViewModel Search(string query) { var model = new ProductListViewModel(); model.FeaturedProducts = NHibernate.Search.Search.CreateFullTextSession(_session) .CreateFullTextQuery<Product>("Name:Boots").List<Product>(); return model; }