public async Task <IEnumerable <IVehicleMake> > GetAll(VehicleFilters filters, VehicleSorting sorting, VehiclePaging paging)
        {
            IQueryable <VehicleMakeEntityModel> vehicles = _genericRepository.GetAll();


            if (filters.ShouldApplyFilters())
            {
                vehicles = vehicles.Where(m => m.Name.Contains(filters.FilterBy) || m.Abrv.Contains(filters.FilterBy));
            }

            paging.TotalCount = vehicles.Count();
            switch (sorting.SortBy)
            {
            case "name_desc":
                vehicles = vehicles.OrderByDescending(v => v.Name);
                break;

            case "Abrv":
                vehicles = vehicles.OrderBy(v => v.Abrv);
                break;

            case "abrv_desc":
                vehicles = vehicles.OrderByDescending(v => v.Abrv);
                break;

            default:
                vehicles = vehicles.OrderBy(v => v.Name);
                break;
            }


            return(await vehicles.Skip(paging.ItemsToSkip).Take(paging.ResultsPerPage).ProjectTo <VehicleMake>(_mapperConfiguration).ToListAsync());
        }
Пример #2
0
        // Vehicle Make
        public async Task <IEnumerable <VehicleMake> > GetVehicleMakeList(VehicleFilters filters, VehicleSorting sorting, VehiclePaging paging)
        {
            IQueryable <VehicleMake> vehicles = from vehicle in _entities.VehicleMakes
                                                select vehicle;

            //filter/find
            if (filters.ShouldApplyFilters())
            {
                vehicles = vehicles.Where(m => m.Name.Contains(filters.FilterBy) || m.Abrv.Contains(filters.FilterBy));
            }

            paging.TotalCount = vehicles.Count();
            // sort
            switch (sorting.SortBy)
            {
            case "name_desc":
                vehicles = vehicles.OrderByDescending(v => v.Name);
                break;

            case "Abrv":
                vehicles = vehicles.OrderBy(v => v.Abrv);
                break;

            case "abrv_desc":
                vehicles = vehicles.OrderByDescending(v => v.Abrv);
                break;

            default:     // sort by name
                vehicles = vehicles.OrderBy(v => v.Name);
                break;
            }

            return(await vehicles.Skip(paging.ItemsToSkip).Take(paging.ResultsPerPage).ToListAsync());
        }
Пример #3
0
        public async Task <IEnumerable <VehicleModel> > GetVehicleModelList(VehicleFilters filters, VehicleSorting sorting, VehiclePaging paging)
        {
            IQueryable <VehicleModel> models = from model in _entities.VehicleModels
                                               select model;

            if (filters.ShouldApplyFilters())
            {
                models = models.Where(m => m.Name.Contains(filters.FilterBy) ||
                                      m.Abrv.Contains(filters.FilterBy) ||
                                      m.MakeId.ToString().Contains(filters.FilterBy));
            }

            paging.TotalCount = models.Count();
            // sort
            switch (sorting.SortBy)
            {
            case "name_desc":
                models = models.OrderByDescending(v => v.Name);
                break;

            case "Abrv":
                models = models.OrderBy(v => v.Abrv);
                break;

            case "abrv_desc":
                models = models.OrderByDescending(v => v.Abrv);
                break;

            case "MakeId":
                models = models.OrderBy(v => v.MakeId);
                break;

            case "makeid_desc":
                models = models.OrderByDescending(v => v.MakeId);
                break;

            default:     // sort by name
                models = models.OrderBy(v => v.Name);
                break;
            }
            return(await models.Skip(paging.ItemsToSkip).Take(paging.ResultsPerPage).ToListAsync());
        }