示例#1
0
        public async Task <ActionResult <PaginatedResult <AccessionSection> > > GetRunsFromAccession(string genbank,
                                                                                                     [FromQuery] int page,
                                                                                                     [FromQuery] int itemsPerPage,
                                                                                                     [FromQuery] string?pctId, // [int-int]
                                                                                                     [FromQuery] string?cvgPct)
        {
            try
            {
                var items = _context.AccessionSections.Where(a => a.Acc == genbank);
                if (pctId != null)
                {
                    (int low, int high)pctIdLimits = Utilities.parseQueryParameterRange(pctId);
                    items = items.Where(a => a.PctId >= pctIdLimits.low && a.PctId <= pctIdLimits.high);
                }
                if (cvgPct != null)
                {
                    (int low, int high)scoreLimits = Utilities.parseQueryParameterRange(cvgPct);
                    items = items.Where(a => a.CvgPct >= scoreLimits.low && a.CvgPct <= scoreLimits.high);
                }
                var accs = await items.OrderByDescending(a => a.CvgPct)
                           .Skip((page - 1) * itemsPerPage)
                           .Take(itemsPerPage).ToListAsync();

                int numPages;
                var totalResults = await items.CountAsync();

                if (totalResults % itemsPerPage != 0)
                {
                    numPages = (totalResults / itemsPerPage) + 1;
                }
                else
                {
                    numPages = totalResults / itemsPerPage;
                }

                var paginatedResult = new PaginatedResult <AccessionSection>
                {
                    Items         = accs,
                    NumberOfPages = numPages
                };
                return(paginatedResult);
            }
            catch (ArgumentException)
            {
                return(BadRequest());
            }
        }
示例#2
0
        public async Task <ActionResult <PaginatedResult <FamilySection> > > GetRunsFromFamily(string family,
                                                                                               [FromQuery] int page,
                                                                                               [FromQuery] int itemsPerPage,
                                                                                               [FromQuery] string?pctId, // [int-int]
                                                                                               [FromQuery] string?score)
        {
            try
            {
                var items = _context.FamilySections.Where(f => f.Family == family);
                if (pctId != null)
                {
                    (int low, int high)pctIdLimits = Utilities.parseQueryParameterRange(pctId);
                    items = items.Where(f => f.PctId >= pctIdLimits.low && f.PctId <= pctIdLimits.high);
                }
                if (score != null)
                {
                    (int low, int high)scoreLimits = Utilities.parseQueryParameterRange(score);
                    items = items.Where(f => f.Score >= scoreLimits.low && f.Score <= scoreLimits.high);
                }
                var families = await items.OrderByDescending(f => f.Score)
                               .Skip((page - 1) * itemsPerPage)
                               .Take(itemsPerPage).ToListAsync();

                int numPages;
                var totalResults = await items.CountAsync();

                if (totalResults % itemsPerPage != 0)
                {
                    numPages = (totalResults / itemsPerPage) + 1;
                }
                else
                {
                    numPages = totalResults / itemsPerPage;
                }

                var paginatedResult = new PaginatedResult <FamilySection>
                {
                    Items         = families,
                    NumberOfPages = numPages
                };
                return(paginatedResult);
            }
            catch (ArgumentException)
            {
                return(BadRequest());
            }
        }