public IActionResult Index() { CatalogueViewModel vm = new CatalogueViewModel(); // only build the catalogue once if (HttpContext.Session.GetObject <List <Brand> >(SessionVars.Brands) == null) { try { BrandModel brandModel = new BrandModel(_db); // now load the Brands List <Brand> Brands = brandModel.GetAll(); HttpContext.Session.SetObject(SessionVars.Brands, Brands); vm.SetBrands(HttpContext.Session.GetObject <List <Brand> >(SessionVars.Brands)); } catch (Exception ex) { ViewBag.Message = "Catalogue Problem - " + ex.Message; } } else { vm.SetBrands(HttpContext.Session.GetObject <List <Brand> >(SessionVars.Brands)); } GetAllProducts(); return(View(vm)); }
public IActionResult Index(BrandViewModel vm) { // only build the catalogue once if (HttpContext.Session.Get <List <Brand> >("brands") == null) { // no session information so let's go to the database try { BrandModel brandModel = new BrandModel(_db); // now load the categories List <Brand> brands = brandModel.GetAll(); HttpContext.Session.Set <List <Brand> >("brands", brands); vm.SetBrands(brands); } catch (Exception ex) { ViewBag.Message = "Catalogue Problem - " + ex.Message; } } else { // no need to go back to the database as information is already in the session vm.SetBrands(HttpContext.Session.Get <List <Brand> >("brands")); } return(View(vm)); }
public IActionResult Index(BrandViewModel vm) { // Only build the catalogue once if (HttpContext.Session.Get <List <Brand> >(SessionVars.Brands) == null) { // no session information so let's go to the database try { BrandModel categoryModel = new BrandModel(_db); // now load the categories List <Brand> categories = categoryModel.GetAll(); HttpContext.Session.Set <List <Brand> >(SessionVars.Brands, categories); vm.SetBrands(categories); } catch (Exception ex) { ViewBag.Message = "Catalogue Problem - " + ex.Message; } } else { // no need to go back to the database as information is already in the session vm.SetBrands(HttpContext.Session.Get <List <Brand> >(SessionVars.Brands)); ProductModel itemModel = new ProductModel(_db); vm.Products = itemModel.GetAllByBrand(vm.BrandId); } return(View(vm)); }