Advertisement
Guest User

Untitled

a guest
May 20th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. public IActionResult Index(BrandViewModel vm)
  2. {
  3. // only build the catalogue once
  4. if (HttpContext.Session.Get<List<Brand>>("brands") == null)
  5. {
  6. // no session information so let's go to the database
  7. try
  8. {
  9. BrandModel brandModel = new BrandModel(_db);
  10. // now load the categories
  11. List<Brand> brands = brandModel.GetAll();
  12. HttpContext.Session.Set<List<Brand>>("brands", brands);
  13. vm.SetBrands(brands);
  14. }
  15. catch (Exception ex)
  16. {
  17. ViewBag.Message = "Catalogue Problem - " + ex.Message;
  18. }
  19. }
  20. else
  21. {
  22. // no need to go back to the database as information is already in the session
  23. vm.SetBrands(HttpContext.Session.Get<List<Brand>>("brands"));
  24. ProductItemModel itemModel = new ProductItemModel(_db);
  25. vm.ProductItems = itemModel.getAllByBrand(vm.Id);
  26. }
  27. return View(vm);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement