public virtual async Task <GetAllSolutionOutput> GetAllSolutionWithFilter(GetAllSolutionFilter filter) { filter.Keyword ??= ""; var containsKw = new Func <string, bool>(a => a.Contains(filter.Keyword)); var contentCt = new Func <Problem, Article.Article, bool>((p, a) => containsKw(p.Url) || containsKw(p.Name) || containsKw(p.Description) || containsKw(a.Title) || containsKw(a.Content)); var query = _problemSolutionManager.MakeQuery().AsEnumerable() .WhereIf(filter.UserId != 0, s => s.CreatorUserId == filter.UserId) .WhereIf(filter.Keyword != "", s => contentCt(s.Problem, s.Solution) || (filter.TypeIds != null && s.Problem.Types.Any(t => filter.TypeIds.Contains(t.ProblemTypeId)))) .ToList(); return(await Task.Run(() => { return new GetAllSolutionOutput { Solutions = query .Skip(filter.SkipCount) .Take(filter.MaxResultCount) .OrderByDescending(s => s.CreationTime) .Select(SolutionToDto), AllResultCount = query.Count(), }; })); }
public async Task <ActionResult> Index(int page, int user, string keyword) { var filter = new GetAllSolutionFilter { UserId = user, Keyword = keyword ?? "", TypeIds = keyword.IsNullOrEmpty() ? null : (await _problemAppService.GetAllProblemTypes(keyword)).Select(t => t.Id), MaxResultCount = PageSize, SkipCount = (page <= 1 ? 0 : page - 1) * PageSize }; var res = await _problemAppService.GetAllSolutionWithFilter(filter); return(View("Index", new IndexViewModel { Solutions = res, Filter = filter })); }