Пример #1
0
        public async Task <PagedResponse <IEnumerable <Entity> > > Handle(GetPositionsQuery request, CancellationToken cancellationToken)
        {
            var validFilter = request;
            var pagination  = request;

            //filtered fields security
            if (!string.IsNullOrEmpty(validFilter.Fields))
            {
                //limit to fields in view model
                validFilter.Fields = _modelHelper.ValidateModelFields <GetPositionsViewModel>(validFilter.Fields);
            }
            if (string.IsNullOrEmpty(validFilter.Fields))
            {
                //default fields from view model
                validFilter.Fields = _modelHelper.GetModelFields <GetPositionsViewModel>();
            }
            // query based on filter
            var entityPositions = await _positionRepository.GetPagedPositionReponseAsync(validFilter);

            var          data        = entityPositions.data;
            RecordsCount recordCount = entityPositions.recordsCount;

            // response wrapper
            return(new PagedResponse <IEnumerable <Entity> >(data, validFilter.PageNumber, validFilter.PageSize, recordCount));
        }
Пример #2
0
        public async Task <PagedDataTableResponse <IEnumerable <Entity> > > Handle(PagedPositionsQuery request, CancellationToken cancellationToken)
        {
            var validFilter = new GetPositionsQuery();

            // Draw map to PageNumber
            validFilter.PageNumber = (request.Start / request.Length) + 1;
            // Length map to PageSize
            validFilter.PageSize = request.Length;

            // Map order > OrderBy
            var colOrder = request.Order[0];

            switch (colOrder.Column)
            {
            case 0:
                validFilter.OrderBy = colOrder.Dir == "asc" ? "PositionNumber" : "PositionNumber DESC";
                break;

            case 1:
                validFilter.OrderBy = colOrder.Dir == "asc" ? "PositionTitle" : "PositionTitle DESC";
                break;

            case 2:
                validFilter.OrderBy = colOrder.Dir == "asc" ? "PositionDescription" : "PositionDescription DESC";
                break;
            }

            // Map Search > searchable columns
            if (!string.IsNullOrEmpty(request.Search.Value))
            {
                //limit to fields in view model
                validFilter.PositionNumber = request.Search.Value;
                validFilter.PositionTitle  = request.Search.Value;
            }
            if (string.IsNullOrEmpty(validFilter.Fields))
            {
                //default fields from view model
                validFilter.Fields = _modelHelper.GetModelFields <GetPositionsViewModel>();
            }
            // query based on filter
            var entityPositions = await _positionRepository.GetPagedPositionReponseAsync(validFilter);

            var          data        = entityPositions.data;
            RecordsCount recordCount = entityPositions.recordsCount;

            // response wrapper
            return(new PagedDataTableResponse <IEnumerable <Entity> >(data, request.Draw, recordCount));
        }
        public async Task <PagedResponse <IEnumerable <Entity> > > Handle(GetEmployeesQuery request, CancellationToken cancellationToken)
        {
            var validFilter = request;

            //filtered fields security
            if (!string.IsNullOrEmpty(validFilter.Fields))
            {
                //limit to fields in view model
                validFilter.Fields = _modelHelper.ValidateModelFields <GetEmployeesViewModel>(validFilter.Fields);
            }
            if (string.IsNullOrEmpty(validFilter.Fields))
            {
                //default fields from view model
                validFilter.Fields = _modelHelper.GetModelFields <GetEmployeesViewModel>();
            }
            // query based on filter
            var entityEmployees = await _employeeRepository.GetPagedEmployeeReponseAsync(validFilter);

            // response wrapper
            return(new PagedResponse <IEnumerable <Entity> >(entityEmployees, validFilter.PageNumber, validFilter.PageSize));
        }