public async Task <PagedResultDto <GetCityForView> > GetAll(GetAllCitiesInput input)
        {
            var filteredCities = _cityRepository.GetAll()
                                 .WhereIf(!string.IsNullOrWhiteSpace(input.Filter), e => false || e.Name.Contains(input.Filter))
                                 .WhereIf(!string.IsNullOrWhiteSpace(input.NameFilter), e => e.Name.ToLower() == input.NameFilter.ToLower().Trim());


            var query = (from o in filteredCities
                         select new GetCityForView()
            {
                City = ObjectMapper.Map <CityDto>(o),
            })
                        .WhereIf(!string.IsNullOrWhiteSpace(input.UserNameFilter), e => e.UserName.ToLower() == input.UserNameFilter.ToLower().Trim());

            var totalCount = await query.CountAsync();

            var cities = await query
                         .OrderBy(input.Sorting ?? "city.id asc")
                         .PageBy(input)
                         .ToListAsync();

            return(new PagedResultDto <GetCityForView>(
                       totalCount,
                       cities
                       ));
        }
Пример #2
0
        public async Task <PagedResultDto <GetCityForViewDto> > GetAll(GetAllCitiesInput input)
        {
            var filteredCities = _cityRepository.GetAll()
                                 .WhereIf(!string.IsNullOrWhiteSpace(input.Filter), e => false || e.Code.Contains(input.Filter) || e.Name.Contains(input.Filter) || e.DisplayName.Contains(input.Filter) || e.Country.Contains(input.Filter));

            var pagedAndFilteredCities = filteredCities
                                         .OrderBy(input.Sorting ?? "id asc")
                                         .PageBy(input);

            var cities = from o in pagedAndFilteredCities
                         select new GetCityForViewDto()
            {
                City = new CityDto
                {
                    Code        = o.Code,
                    Name        = o.Name,
                    DisplayName = o.DisplayName,
                    Country     = o.Country,
                    Id          = o.Id
                }
            };

            var totalCount = await filteredCities.CountAsync();

            return(new PagedResultDto <GetCityForViewDto>(
                       totalCount,
                       await cities.ToListAsync()
                       ));
        }