Example #1
0
        public async Task <SearchVm <QueueVm> > GetAllDataSourceQueues(SearchQueryM query)
        {
            var sortBy = string.IsNullOrEmpty(query.SortBy)
                ? "Id"
                : query.SortBy;

            var orderRule = query.OrderByValue == OrderRule.Asc && !string.IsNullOrEmpty(query.SortBy)
                ? "ASC"
                : "DESC";

            var filtered = _dbContext.DataSourceQueues
                           .Include(x => x.DataSource)
                           .Include(x => x.User)
                           .AsNoTracking();

            if (query.Status.HasValue)
            {
                filtered = filtered.Where(x => x.Status == query.Status.Value);
            }

            if (query.DateFrom.HasValue && query.DateTo.HasValue)
            {
                filtered = filtered.Where(x => x.StartImportDate >= query.DateFrom.Value &&
                                          x.StartImportDate <= query.DateTo.Value);
            }
            else
            {
                if (query.DateFrom.HasValue)
                {
                    filtered = filtered.Where(x => x.StartImportDate >= query.DateFrom.Value);
                }

                if (query.DateTo.HasValue)
                {
                    filtered = filtered.Where(x => x.StartImportDate <= query.DateTo.Value);
                }
            }

            filtered = filtered.OrderBy($"{sortBy} {orderRule}");

            var total = await filtered.CountAsync();

            var result = await filtered
                         .Skip(Pagination.CalculateSkip(query.PageSize, query.Page, total))
                         .Take(query.PageSize)
                         .AsNoTracking()
                         .ToListAsync();

            return(SearchVm <QueueVm> .Create(result.Select(QueueVm.Create), total));
        }
Example #2
0
 public async Task <IActionResult> GetAllDataSourceQueues([FromQuery] SearchQueryM query) =>
 Ok(await _svc.GetAllDataSourceQueues(query));