public IActionResult Index(SortingInputModel sorting, int pageId = 1) { if (sorting.OrderBy == null) { sorting = new SortingInputModel() { OrderBy = "Date", }; } var orderBySelector = GetOrderBySelector(sorting); var skip = DefaultItemsPerPage * (pageId - 1); var rankingsViewModel = new RankingsViewModel() { StartRank = skip + 1, Ranking = this.applicationUsersService .GetMany <RankingViewModel>( orderBySelector: orderBySelector, asc: false, skip: skip, take: DefaultItemsPerPage), Common = new CommonViewModel() { Pagination = this.GetPaginationModel(pageId, this.applicationUsersService.Count()), Sorting = sorting, }, }; return(this.View(rankingsViewModel)); }
public IActionResult Index(SortingInputModel sorting, int pageId = 1) { if (sorting.OrderBy == null) { sorting = new SortingInputModel() { OrderBy = "Date", Ascending = false, }; } var orderBySelector = GetOrderBySelector(sorting); var skip = DefaultItemsPerPage * (pageId - 1); var ascentsViewModel = new AscentsViewModel() { Ascents = this.ascentsService .GetMany <AscentViewModel>( orderBySelector: orderBySelector, asc: sorting.Ascending, skip: skip, take: DefaultItemsPerPage), Common = new CommonViewModel() { Pagination = this.GetPaginationModel(pageId, this.ascentsService.Count()), Sorting = sorting, }, }; return(this.View(ascentsViewModel)); }
private static Expression <Func <Gym, object> > GetOrderBySelector(SortingInputModel sortingModel) { Expression <Func <Gym, object> > orderBySelect; orderBySelect = sortingModel.OrderBy switch { "Name" => x => x.Name, "BouldersCount" => x => x.Boulders.Count, _ => x => x.Name, }; return(orderBySelect); }
private static Expression <Func <Ascent, object> > GetOrderBySelector(SortingInputModel sortingModel) { Expression <Func <Ascent, object> > orderBySelect; orderBySelect = sortingModel.OrderBy switch { "Date" => x => x.Date, "Grade" => x => x.Grade.Text, "Stars" => x => x.Stars, _ => x => x.Date, }; return(orderBySelect); }
private static Expression <Func <Country, object> > GetOrderBySelector(SortingInputModel sortingModel) { Expression <Func <Country, object> > orderBySelect; orderBySelect = sortingModel.OrderBy switch { "Name" => x => x.Name, "CountryCode" => x => x.CountryCode, "CitiesCount" => x => x.Cities.Count, _ => x => x.Name, }; return(orderBySelect); }
private static Expression <Func <Boulder, object> > GetOrderBySelector(SortingInputModel sortingModel) { Expression <Func <Boulder, object> > orderBySelect; orderBySelect = sortingModel.OrderBy switch { "Date" => x => x.CreatedOn, "Grade" => x => x.Grade.Text, "Name" => x => x.Name, "AscentsCount" => x => x.Ascents.Count, _ => x => x.CreatedOn, }; return(orderBySelect); }
private static Expression <Func <ApplicationUser, object> > GetOrderBySelector(SortingInputModel sortingModel) { Expression <Func <ApplicationUser, object> > orderBySelect; orderBySelect = sortingModel.OrderBy switch { "Weekly" => x => x.Points.Weekly, "Monthly" => x => x.Points.Monthly, "Yearly" => x => x.Points.Yearly, "AllTime" => x => x.Points.AllTime, _ => x => x.Points.Weekly, }; return(orderBySelect); }