public async Task <SearchResult <Currency> > Search(CurrencySearchPattern searchPattern)
        {
            IQueryable <Currency> query = _ctx.Currencies.AsQueryable();
            int totalCount = query.Count();

            // filters
            if (!String.IsNullOrWhiteSpace(searchPattern.SearchString))
            {
                string searchString = searchPattern.SearchString.Trim();
                query = query.Where(x =>
                                    x.Name.Contains(searchString));
            }

            // sorting
            query = query.OrderByDescending(x => x.Id);

            int filteredCount = query.Count();

            // taking
            query = query.Skip(searchPattern.Skip()).Take(searchPattern.Take());

            return(new SearchResult <Currency>
            {
                Items = await query.ToListAsync(),
                TotalCount = totalCount,
                FilteredCount = filteredCount
            });
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Search(int pageNumber, int onPage, string searchString)
        {
            var abc = new CurrencySearchPattern
            {
                PageNumber   = pageNumber,
                OnPage       = onPage,
                SearchString = searchString
            };
            SearchResult <Currency> searchResult = await currencyRepository.Search(abc);

            return(Ok(new SearchResult <CurrencyDto>
            {
                Items = searchResult.Items.Map(),
                TotalCount = searchResult.TotalCount,
                FilteredCount = searchResult.FilteredCount
            }));
        }