Пример #1
0
        public Task <List <Vehicle> > GetVehicles(PagePref page)
        {
            var query = context.Vehicles
                        .Include(x => x.Features)
                        .ThenInclude(x => x.Feature)
                        .Include(x => x.Model)
                        .ThenInclude(x => x.Make);

            var columnsMap = new Dictionary <string, Func <Vehicle, object> > {
                ["model"]   = x => x.Model.Name,
                ["make"]    = x => x.Model.Make.Name,
                ["contact"] = x => x.ContactName,
            };

            //TODO: refactor badThing to Iqueryble

            if (string.IsNullOrWhiteSpace(page.Sorting) || !columnsMap.ContainsKey(page.Sorting))
            {
                return(query.Skip(page.PageLength * page.PageNumber).Take(page.PageLength).ToListAsync());
            }

            var badThing = page.IsDescending ?
                           query.OrderByDescending(columnsMap[page.Sorting]) :
                           query.OrderBy(columnsMap[page.Sorting]);

            badThing.Skip(page.PageLength * page.PageNumber).Take(page.PageLength);

            return(query.ToListAsync());
        }
Пример #2
0
        public async Task <IActionResult> Get(PagePref page)
        {
            var vehicles = await this.vehicleRepository.GetVehicles(page);

            var response = mapper.Map <IEnumerable <Vehicle>, IEnumerable <VehicleResource> >(vehicles);

            return(Ok(response));
        }