public async Task <JsonResult> SearchCommunity(GetCommunityInput searchModel) { if (searchModel == null) { return(Json(new { success = false, msg = "无效参数" })); } try { await _communityAppService.GetPagedCommunitysAsync(searchModel); return(Json(new { success = true, msg = "" })); } catch (Exception e) { return(Json(new { success = false, msg = "保存失败" })); } }
/// <summary> /// 根据查询条件获取圈子信息表分页列表 /// </summary> public async Task <PagedResultDto <CommunityListDto> > GetPagedCommunitysAsync(GetCommunityInput input) { var query = _communityRepositoryAsNoTrack; //TODO:根据传入的参数添加过滤条件 DateTime now = DateTime.Now; DateTime?expire = null; if (input.RefreshExpire > 0) { expire = now.AddDays((-1) * input.RefreshExpire); } query = query.WhereIf(input.Id > 0, c => c.Id == input.Id) .WhereIf(!string.IsNullOrEmpty(input.Title), c => c.Detail.Contains(input.Title)) .WhereIf(input.CommunityCategoryId > 0, c => c.CommunityCategoryId == input.CommunityCategoryId) .WhereIf(input.UserId > 0, c => c.UserId == input.UserId) .WhereIf(expire != null, c => c.RefreshDate <= expire) .WhereIf(input.VerifyStatus != VerifyStatus.Invalid, c => c.VerifyStatus == input.VerifyStatus) .WhereIf(input.ReleaseStatus != ReleaseStatus.Invalid, c => c.ReleaseStatus == input.ReleaseStatus) .WhereIf(input.FromTime != null, c => c.CreationTime >= input.FromTime) .WhereIf(input.EndTime != null, c => c.CreationTime <= input.EndTime); var communityCount = await query.CountAsync(); switch (input.Sorting.ToLower()) { case "refreshdate": query = query.OrderByDescending(c => c.RefreshDate); break; default: query = query.OrderByDescending(c => c.CreationTime); break; } var communitys = await query .PageBy(input) .ToListAsync(); var communityListDtos = communitys.MapTo <List <CommunityListDto> >(); return(new PagedResultDto <CommunityListDto>( communityCount, communityListDtos )); }