Esempio n. 1
0
        public async Task <IEnumerable <Vehicle> > GetVehicles(VehicleQuery queryObject)
        {
            var query = context.Vehicles
                        .Include(v => v.Model)
                        .ThenInclude(m => m.Make)
                        .Include(v => v.Features)
                        .ThenInclude(vf => vf.Feature)
                        .AsQueryable();

            if (queryObject.MakeId.HasValue)
            {
                query = query.Where(v => v.Model.MakeId == queryObject.MakeId);
            }

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

            query = IQueryableExtensions <Vehicle> .ApplyOrdering(query, queryObject, columnsMap);

            query = IQueryableExtensions <Vehicle> .ApplyPaging(query, queryObject);

            return(await query.ToListAsync());
        }
        public async Task <QueryResult <TrainingRequest> > GetTrainingRequests(TrainingRequestsQuery queryObj)
        {
            var result = new QueryResult <TrainingRequest>();

            IQueryable <TrainingRequest> query = null;

            if (queryObj.ViewAll.HasValue && queryObj.EmployeeId.HasValue == false)
            {
                query = GetQueryableAllTrainingRequests();
            }
            if (queryObj.ViewAll.HasValue == false && queryObj.EmployeeId.HasValue)
            {
                if (queryObj.EmployeeId != null)
                {
                    query = GetQueryableUsersTrainingRequests(queryObj.EmployeeId.Value);
                }
            }
            if (queryObj.ViewAll.HasValue == false && queryObj.EmployeeId.HasValue == false)
            {
                query = GetQueryableAllTrainingRequests();
            }

            query = ApplyFiltering(query, queryObj);
            var columnsMap = new Dictionary <string, Expression <Func <TrainingRequest, object> > >()
            {
                ["status"]       = trainingRequest => trainingRequest.Status,
                ["type"]         = trainingRequest => trainingRequest.TrainingRequestTypeTitle,
                ["date"]         = trainingRequest => trainingRequest.DateCreated,
                ["employeeName"] = trainingRequest => trainingRequest.EmployeeName,
            };

            query             = _queryableExtensions.ApplyOrderingColumnMap(query, queryObj, columnsMap);
            result.TotalItems = await query.CountAsync();

            query        = _queryableExtensions.ApplyPaging(query, queryObj);
            result.Items = await query.ToListAsync();

            return(result);
        }
        public async Task <QueryResult <LetterRequests> > GetLetterRequests(LetterRequestsQuery queryObj)
        {
            var result = new QueryResult <LetterRequests>();
            var query  = GetQueryable();

            query = ApplyFiltering(query, queryObj);
            var columnsMap = new Dictionary <string, Expression <Func <LetterRequests, object> > >()
            {
                ["status"]       = letterRequest => letterRequest.Status,
                ["urgency"]      = letterRequest => letterRequest.Urgency,
                ["employeeName"] = letterRequest => letterRequest.EmployeeName,
                ["type"]         = letterRequest => letterRequest.LetterType.Type,
                ["date"]         = letterRequest => letterRequest.DateCreated,
                ["userId"]       = letterRequest => letterRequest.UserId,
            };

            query             = _queryableExtensions.ApplyOrderingColumnMap(query, queryObj, columnsMap);
            result.TotalItems = await query.CountAsync();

            query        = _queryableExtensions.ApplyPaging(query, queryObj);
            result.Items = await query.ToListAsync();

            return(result);
        }
Esempio n. 4
0
        public async Task <QueryResult <Employee> > GetEmployees(EmployeeQuery queryObj)
        {
            var result = new QueryResult <Employee>();
            var query  = GetQueryable();

            query = ApplyFiltering(query, queryObj);
            var columnsMap = new Dictionary <string, Expression <Func <Employee, object> > >()
            {
                ["username"]    = employee => employee.Username,
                ["fullname"]    = employee => employee.PersonalInfo.FullName,
                ["empId"]       = employee => employee.EmpId,
                ["designation"] = employee => employee.Designation,
                ["role"]        = employee => employee.Role.Name,
                ["isActive"]    = employee => employee.IsActive
            };

            query             = _queryableExtensions.ApplyOrderingColumnMap(query, queryObj, columnsMap);
            result.TotalItems = await query.CountAsync();

            query        = _queryableExtensions.ApplyPaging(query, queryObj);
            result.Items = await query.ToListAsync();

            return(result);
        }