public async Task <SearchResult <Tariff> > GetFoundTariff(TarifftSearchPattern searchPattern) { IQueryable <Tariff> query = _DbContext.Tariffs.AsQueryable(); int totalCount = query.Count(); if (!String.IsNullOrWhiteSpace(searchPattern.SearchString)) { string searchString = searchPattern.SearchString.Trim(); query = query.Where(x => x.Name.Contains(searchString)); } query = query.OrderByDescending(x => x.Id); int filteredCount = query.Count(); query = query.Skip(searchPattern.Skip()).Take(searchPattern.Take()); return(new SearchResult <Tariff> { Items = await query.ToListAsync(), TotalCount = totalCount, FilteredCount = filteredCount }); }
public async Task <IActionResult> Get(int pageNumber, int onPage, string searchString) { var abc = new TarifftSearchPattern { PageNumber = pageNumber, OnPage = onPage, SearchString = searchString }; SearchResult <Tariff> searchResult = await tariffRepository.GetFoundTariff(abc); return(Ok(new SearchResult <TariffDto> { Items = searchResult.Items.Map(), TotalCount = searchResult.TotalCount, FilteredCount = searchResult.FilteredCount })); }