public async Task <ActionResult> Info(ManagerSortCriteria criteria = ManagerSortCriteria.Default, int pageNumber = 1) { var sortedManagers = await(Task.Run(() => ManagerService.SortManagers(ManagerService.Managers, criteria))); var pageSize = Convert.ToInt32(ConfigurationManager.AppSettings.Get("PageSize")); var managerViewModel = new ManagerViewModel { PageInfo = new PageInfo(currentPageNumber: pageNumber, pageSize: pageSize, totalItems: sortedManagers.Count()), ManagersPerPage = PageInfo.GetItemsPerPage(sortedManagers, pageNumber, pageSize), Filters = new SelectList(Enum.GetValues(typeof(ManagerSortCriteria)), criteria) }; return(PartialView(managerViewModel)); }
public static IEnumerable <Manager> SortManagers(IEnumerable <Manager> managers, ManagerSortCriteria managerSortCriteria) { switch (managerSortCriteria) { case ManagerSortCriteria.Default: return(managers.OrderBy(man => man.Id)); case ManagerSortCriteria.Ascending: return(managers.OrderBy(man => man.Name)); case ManagerSortCriteria.Descending: return(managers.OrderByDescending(man => man.Name)); default: return(null); } }