public async Task OnGetAsync(int?pageNo) { var pageIndex = ValuesHelper.GetPageIndex(pageNo); //static IQueryable<Workout> queryModifier(IQueryable<Workout> q) => q.Include(w => w.Start).OrderByDescending(w => w.Start); var workoutList = await _repository.GetList(new WorkoutsSortedByDateWithPagingSpecification(pageIndex, _pageSize)) .ConfigureAwait(false); //var workoutList = await _repository.GetList(w => w.Start, true, _pageSize, pageIndex) var totalCount = await _repository.GetCount() .ConfigureAwait(false); Workouts = new ListWithPaging <WorkoutViewModel>(totalCount, pageIndex, _pageSize, nameof(pageNo)); foreach (var item in workoutList) { Workouts.Add(_mapper.Map <WorkoutViewModel>(item)); } }
public async Task OnGet(int?pageNo, string sortBy, bool?descending) { Expression <Func <WorkoutInterval, object> > sortSelector; switch (sortBy) { case DistanceSortKey: { sortSelector = i => i.Distance; break; } case DurationSortKey: { sortSelector = i => i.Duration; break; } case StrokeCountSortKey: { sortSelector = i => i.StrokeCount; break; } case PaceSortKey: { sortSelector = i => i.Pace; break; } case SwolfSortKey: { sortSelector = i => i.Swolf; break; } default: { sortSelector = i => i.Workout.WorkoutDate; break; } } var newSortOrder = string.IsNullOrWhiteSpace(sortBy) ? DateSortKey : sortBy; var sortDescending = descending ?? true; var pageIndex = ValuesHelper.GetPageIndex(pageNo); var intervals = await _intervalRepository.GetList(new SortedIntervalsByTypeSpecification(SelectedIntervalType, sortSelector, sortDescending, pageIndex, _pageSize)) //var intervals = await _intervalRepository.GetList( // q => q // .Where(i => i.WorkoutIntervalTypeId == SelectedIntervalType) // .Include(i => i.WorkoutIntervalType) // .Include(i => i.Workout), // _pageSize, pageIndex, sortSelector, sortDescending) .ConfigureAwait(false); //var intervals = await _intervalRepository.GetList(i => i.WorkoutIntervalTypeId == SelectedIntervalType, sortSelector, sortDescending, _pageSize, pageIndex, i => i.WorkoutIntervalType, i => i.Workout) var totalCount = await _intervalRepository.GetCount(new IntervalsByTypeSpecification(SelectedIntervalType)) //var totalCount = await _intervalRepository.GetCount(i => i.WorkoutIntervalTypeId == SelectedIntervalType) .ConfigureAwait(false); var sortKeys = new Dictionary <string, string> { { DateFieldName, DateSortKey }, { DistanceFieldName, DistanceSortKey }, { DurationFieldName, DurationSortKey }, { StrokeCountFieldName, StrokeCountSortKey }, { PaceFieldName, PaceSortKey }, { SwolfFieldName, SwolfSortKey } }; Intervals = new ListWithPagingAndSorting <WorkoutIntervalViewModel>(totalCount, pageIndex, _pageSize, nameof(pageNo), nameof(sortBy), nameof(descending), newSortOrder, sortDescending, sortKeys); foreach (var interval in intervals) { var displayItem = _mapper.Map <WorkoutIntervalViewModel>(interval); displayItem.WorkoutName = interval.Workout.Name; displayItem.WorkoutDate = interval.Workout.WorkoutDate; Intervals.Add(displayItem); } Intervals.FirstPageRouteValues.Add(nameof(SelectedIntervalType), SelectedIntervalType.ToStringInvariant()); Intervals.LastPageRouteValues.Add(nameof(SelectedIntervalType), SelectedIntervalType.ToStringInvariant()); Intervals.PrevPageRouteValues.Add(nameof(SelectedIntervalType), SelectedIntervalType.ToStringInvariant()); Intervals.NextPageRouteValues.Add(nameof(SelectedIntervalType), SelectedIntervalType.ToStringInvariant()); foreach (var routeValues in Intervals.SortRouteValues) { routeValues.Value.Add(nameof(SelectedIntervalType), SelectedIntervalType.ToStringInvariant()); } var intervalTypes = await _intervalTypeRepository.GetList() .ConfigureAwait(false); WorkoutIntervalTypeSelectList = new SelectList(intervalTypes, "Id", "Name"); }