private IQueryable <UnionInfo> GetFilteredQuery(GetUnionInfoInput input) { var query = QueryableExtensions.WhereIf(_unionInfoRepository.GetAllIncluding(p => p.StateInfo), !input.Filter.IsNullOrWhiteSpace(), u => u.UnionName.Contains(input.Filter) || u.Code.Contains(input.Filter) || u.Name.Contains(input.Filter) || u.Family.Contains(input.Filter) || u.NationalCode.Replace("-", "").Contains(input.Filter) || u.StateInfo.Name.Contains(input.Filter)); return(query); }
public async Task <PagedResultDto <UnionInfoListDto> > GetUnionInfo(GetUnionInfoInput input) { var query = GetFilteredQuery(input); var user = await UserManager.GetUserByIdAsync(AbpSession.GetUserId()); var isAdmin = await UserManager.IsInRoleAsync(user, StaticRoleNames.Host.Admin); var isSysAdmin = await UserManager.IsInRoleAsync(user, StaticRoleNames.Host.SysAdmin); var isStateAdmin = await UserManager.IsInRoleAsync(user, StaticRoleNames.Host.StateAdmin); var isCityAdmin = await UserManager.IsInRoleAsync(user, StaticRoleNames.Host.CityAdmin); if (isAdmin || isSysAdmin) { query = query; } else if (isStateAdmin) { var union = _unionInfoRepository.FirstOrDefault(x => x.UserId == AbpSession.UserId); query = query.Where(x => x.Id == union.Id); } else { query = query.Where(x => false); } var userCount = await query.CountAsync(); var unionInfos = await query .OrderBy(input.Sorting) .PageBy(input) .ToListAsync(); var unionInfosListDto = ObjectMapper.Map <List <UnionInfoListDto> >(unionInfos); return(new PagedResultDto <UnionInfoListDto>( userCount, unionInfosListDto )); }