public IActionResult Index(string sortOrder) { ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; ViewBag.TypeSortParm = sortOrder == "type" ? "type_desc" : "type"; if (HttpContext.Session.Get("Username") != null) { userID = Convert.ToInt32(HttpContext.Session.GetInt32("UserID")); try { IEnumerable <Item> items = new List <Item>(collectionRepository.GetAllItems(userID)); switch (sortOrder) { case "name_desc": items = items.OrderByDescending(s => s.Title).ThenByDescending(s => s.ItemType); break; case "type": items = items.OrderBy(s => s.ItemType).ThenBy(s => s.Title); break; case "type_desc": items = items.OrderByDescending(s => s.ItemType).ThenByDescending(s => s.Title); break; default: items = items.OrderBy(s => s.Title).ThenBy(s => s.ItemType); break; } return(View(items)); } catch (Exception e) { string message = e.Message; return(View("Error", "Database")); } } return(RedirectToAction("Login", "User")); }