public ActionResult Detail(int id) { var data = new ProductListViewModel(); //if(id==0) //data.ContentPage = Models.Page.LoadID(id, Otherwise.NotFound); //if (data.ContentPage == null) throw new Exception("Product page not found"); data.Categories = ProductCategoryList.LoadByPageID(id).Active; return(View("Products", data)); }
public async Task <IActionResult> OnGetAsync(string categoryCode, string brandCode) { ProductBrandList = await _catalogServcie.GetCatalogBrand(); ProductCategoryList = await _catalogServcie.GetCatalogCategory(); var productList = await _catalogServcie.GetCatalog(); // filter products by brand if (!string.IsNullOrWhiteSpace(brandCode)) { ProductList = productList.Where(p => p.BrandCode == brandCode); } // filter products by category if (!string.IsNullOrWhiteSpace(categoryCode)) { ProductList = productList.Where(p => string.Equals(p.ParentCategoryCode, categoryCode) || string.Equals(p.ChildCategoryCode, categoryCode)); } if (string.IsNullOrWhiteSpace(brandCode) && string.IsNullOrWhiteSpace(categoryCode)) { ProductList = productList; } ProductBrandList = ProductBrandList.Select(x => { x.ProductCount = ProductList.Where(p => p.BrandCode == x.Code).Count(); return(x); }); ProductBrandList = ProductBrandList.Where(x => x.ProductCount > 0).ToList(); ProductCategoryList = ProductCategoryList.Select(x => { x.ProductCount = ProductList.Where(p => p.ParentCategoryCode == x.Code).Count(); return(x); }); ProductCategoryList = ProductCategoryList.Where(x => x.ProductCount > 0).ToList(); PagedCatalog = ProductList.Skip((PageIndex - 1) * PageSize) .Take(PageSize).OrderBy(x => x.Name).ToList(); TotalItems = ProductList.Count(); return(Page()); }
/******************************************************************************************* ******************************************************************************************** * * ●●●●●●●●●●●●●●●●●●●● View ●●●●●●●●●●●●●●●●●●●● * ******************************************************************************************** *******************************************************************************************/ //●Index public IActionResult Index() { using (var db = new ShopDbContext()) { //DBに初期値のデータを入れる ProductImages.Initialize(db); ProductCategoryList.Initialize(db); Product.Initialize(db); Country.Initialize(db); State.Initialize(db); City.Initialize(db); Models.User.Initialize(db); //Index画面に表す6個を呼び出す var model = db.Product.OrderByDescending(n => n.ProductNo).Take(6).ToList(); return(View(model)); } }
// GET: /Home public ActionResult Index() { var data = new ProductListViewModel(); //data.ContentPage = new Page(); //if (data.ContentPage == null) throw new Exception("Product page not found"); data.Categories = ProductCategoryList.LoadActive(); if (data.Categories.Count == 0) { //load some temp data data.Categories.Add(new ProductCategory() { Title = "test11" }); data.Categories[0].Products.Add(new Product() { Title = "prod1" }); data.Categories[0].Products.Add(new Product() { Title = "prod2" }); data.Categories.Add(new ProductCategory() { Title = "test12" }); data.Categories[1].Products.Add(new Product() { Title = "prod11" }); data.Categories[1].Products.Add(new Product() { Title = "prod12" }); data.Categories[1].Products.Add(new Product() { Title = "prod13" }); data.Categories.Add(new ProductCategory() { Title = "test13" }); } return(View("Products", data)); }
// GET: Admin/ProductCategories public async Task <IActionResult> Index(string orderby, string sort, string keyword) { var vm = new ProductCategoryList { Keyword = keyword, OrderBy = orderby, Sort = sort, }; var query = _context.ProductCategories.AsNoTracking().AsQueryable(); var gosort = $"{orderby}_{sort}"; query = gosort switch { "title" => query.OrderBy(s => s.Title), "title_desc" => query.OrderByDescending(s => s.Title), "date" => query.OrderBy(s => s.CreatedDate), "date_desc" => query.OrderByDescending(s => s.CreatedDate), "importance" => query.OrderBy(s => s.Importance), "importance_desc" => query.OrderByDescending(s => s.Importance), _ => query.OrderByDescending(s => s.Id), }; var categories = await query.ProjectTo <ProductCategoryBVM>(_mapper.ConfigurationProvider).ToListAsync(); var list = new List <ProductCategoryBVM>(); foreach (var item in categories.Where(d => d.ParentId == null)) { // vm.Categories.Add(item); LoadCategories(list, item, 0, 0, categories); } if (!string.IsNullOrEmpty(keyword)) { vm.Categories = list.Where(d => d.Title.Contains(keyword)); } else { vm.Categories = list; } return(View(vm)); }
private ProductCategoryList GetProductCategories() { using (var entitiesContext = new ProductsModel.Entities()) { IQueryable<Common.DomainClasses.ProductCategory> query = from productCategory in entitiesContext.ProductCategories orderby productCategory.Name select new Common.DomainClasses.ProductCategory() { Id = productCategory.ProductCategoryID, Name = productCategory.Name }; var result = new ProductCategoryList(); // Note that the query executes on the ToList. foreach (var item in query.ToList()) { result.Add(item); } return result; } }