Exemplo n.º 1
0
        public Task <IPagedList <VehicleModel> > GetPagedModelsAsync(IFilteringModel filterModel, ISortingModel sortingModel, IPagingModel pagingModel)
        {
            Expression <Func <VehicleModel, bool> > filter = null;

            if (filterModel.FilterById != null)
            {
                filter = e => e.MakeId == filterModel.FilterById;
            }

            Func <IQueryable <VehicleModel>, IOrderedQueryable <VehicleModel> > orderBy = sortingModel.SortParameter switch
            {
                "Name" => q => q.OrderBy(e => e.Name),
                "name_desc" => q => q.OrderByDescending(e => e.Name),
                "Abrv" => q => q.OrderBy(e => e.Abrv),
                "abrv_desc" => q => q.OrderByDescending(e => e.Abrv),
                "Make" => q => q.OrderBy(e => e.Make.Name),
                "make_desc" => q => q.OrderByDescending(e => e.Make.Name),
                _ => null,
            };

            return(GetPagedAsync(pagingModel.Page, pagingModel.PageSize, filter, orderBy, "Make"));
        }
Exemplo n.º 2
0
 public Task <IPagedList <VehicleModel> > GetPagedModelsAsync(IFilteringModel filterModel, ISortingModel sortingModel, IPagingModel pagingModel)
 {
     return(_modelRepository.GetPagedModelsAsync(filterModel, sortingModel, pagingModel));
 }
Exemplo n.º 3
0
        public Task <IPagedList <VehicleMake> > GetPagedMakesAsync(IFilteringModel filterModel, ISortingModel sortingModel, IPagingModel pagingModel)
        {
            Expression <Func <VehicleMake, bool> > filter = null;

            if (!string.IsNullOrWhiteSpace(filterModel.Filter))
            {
                filter = e => e.Name.ToUpper().Contains(filterModel.Filter.ToUpper()) ||
                         e.Abrv.ToUpper().Contains(filterModel.Filter.ToUpper());
            }

            Func <IQueryable <VehicleMake>, IOrderedQueryable <VehicleMake> > orderBy = sortingModel.SortParameter switch
            {
                "Name" => q => q.OrderBy(s => s.Name),
                "name_desc" => q => q.OrderByDescending(s => s.Name),
                "Abrv" => q => q.OrderBy(s => s.Abrv),
                "abrv_desc" => q => q.OrderByDescending(s => s.Abrv),
                _ => null,
            };

            return(GetPagedAsync(pagingModel.Page, pagingModel.PageSize, filter, orderBy));
        }