Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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"));
- ProductItemModel itemModel = new ProductItemModel(_db);
- vm.ProductItems = itemModel.getAllByBrand(vm.Id);
- }
- return View(vm);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement