Exemplo n.º 1
0
        public async Task <QueryResult <Vehicule> > GetAllVehiculesAsync(VehiculeQuery querryObj, bool includeRelated = true)
        {
            var result = new QueryResult <Vehicule>();

            if (!includeRelated)
            {
                result.Items = await appDbContext.Vehicules.ToListAsync();

                result.TotalItems = await appDbContext.Vehicules.CountAsync();

                return(result);
            }

            var query = appDbContext.Vehicules.Include(v => v.Model).ThenInclude(m => m.Make).AsQueryable();

            query = query.ApplyFiltering(querryObj);

            var columnsMap = new Dictionary <string, Expression <Func <Vehicule, object> > > {
                ["make"]        = v => v.Model.Make.Name,
                ["model"]       = v => v.Model.Name,
                ["contactName"] = v => v.ContactName,
            };

            query = query.ApplyOrdering(querryObj, columnsMap);

            result.TotalItems = await query.CountAsync();

            query = query.ApplyPaging(querryObj);

            result.Items = await query.ToListAsync();

            return(result);
        }
Exemplo n.º 2
0
 public static IQueryable <Vehicule> ApplyFiltering(this IQueryable <Vehicule> query, VehiculeQuery queryObj)
 {
     if (queryObj.MakeId.HasValue)
     {
         query = query.Where(v => v.Model.MakeId == queryObj.MakeId);
     }
     return(query);
 }