public async Task <IActionResult> GetHistory(PagingInfo pagingInfo) { var history = await _SearchHistoryRepository.GetAll(pagingInfo); IEnumerable <SearchHistoryListModel> model = history.Select(search => SearchHistoryListModel(search)); var total = _SearchHistoryRepository.Count(); var pages = (int)Math.Ceiling(total / (double)pagingInfo.PageSize); var prev = pagingInfo.Page > 0 ? Url.Link(nameof(GetHistory), new { page = pagingInfo.Page - 1, pagingInfo.PageSize }) : null; var next = pagingInfo.Page < pages - 1 ? Url.Link(nameof(GetHistory), new { page = pagingInfo.Page + 1, pagingInfo.PageSize }) : null; var result = new { Prev = prev, Next = next, Total = total, Pages = pages, History = model }; return(Ok(result)); }
public IEnumerable <SearchHistoryViewModel> GetHistory(BaseGetAllRequest request) { var a = searchHistoryRepository.GetAll().Where(x => x.HistoryType == HistoryType.Post); var vm = mapper.Map <IEnumerable <SearchHistoryViewModel> >(a); vm = vm.GroupBy(x => x.PostValue.ContentFilter) .Select(x => x.OrderByDescending(y => y.CreatedDate).FirstOrDefault()) .OrderByDescending(x => x.CreatedDate); if (request.Skip.HasValue && request.Count.HasValue) { vm = vm.Skip(request.Skip.Value).Take(request.Count.Value); } return(vm); }