public async Task <ApiResponse> Handle(GetAllProjectIndicatorsQuery request, CancellationToken cancellationToken)
        {
            ApiResponse           response          = new ApiResponse();
            ProjectIndicatorModel projectIndicators = new ProjectIndicatorModel();

            try
            {
                var indicators = _dbContext.ProjectIndicators
                                 .OrderByDescending(x => x.CreatedDate)
                                 .Where(x => x.IsDeleted == false)
                                 .Select(x => new ProjectIndicatorViewModel
                {
                    IndicatorCode      = x.IndicatorCode,
                    IndicatorName      = x.IndicatorName,
                    ProjectIndicatorId = x.ProjectIndicatorId
                }).AsQueryable();



                if (request.PageIndex != 0 || request.PageSize != 0)
                {
                    indicators = indicators.Skip((request.PageIndex * request.PageSize)).Take(request.PageSize);
                }

                long recordCount = await _dbContext.ProjectIndicators
                                   .Where(x => x.IsDeleted == false).CountAsync();

                var indicatorList = await indicators.ToListAsync();

                if (indicatorList.Any())
                {
                    projectIndicators.ProjectIndicators.AddRange(indicatorList);
                    response.data.ProjectIndicatorList = new ProjectIndicatorModel();
                    response.data.ProjectIndicatorList.ProjectIndicators    = projectIndicators.ProjectIndicators;
                    response.data.ProjectIndicatorList.IndicatorRecordCount = recordCount;
                }

                response.StatusCode = StaticResource.successStatusCode;
                response.Message    = StaticResource.SuccessText;
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + ex;
            }

            return(response);
        }
Exemple #2
0
        public async Task <ApiResponse> Handle(GetProjectIndicatorDetailByIdQuery request, CancellationToken cancellationToken)
        {
            ApiResponse           response          = new ApiResponse();
            ProjectIndicatorModel projectIndicators = new ProjectIndicatorModel();

            try
            {
                if (request.indicatorId == 0)
                {
                    throw new Exception("Project Indicator Id Cannot be 0");
                }

                var indicators = await _dbContext.ProjectIndicators.Include(x => x.ProjectIndicatorQuestions)
                                 .Select(x => new EditIndicatorModel
                {
                    IndicatorCode      = x.IndicatorCode,
                    IndicatorName      = x.IndicatorName,
                    IndicatorId        = x.ProjectIndicatorId,
                    IsDeleted          = x.IsDeleted,
                    IndicatorQuestions = x.ProjectIndicatorQuestions.Select(y => new IndicatorQuestions
                    {
                        QuestionId   = y.IndicatorQuestionId,
                        QuestionText = y.IndicatorQuestion,
                        IsDeleted    = y.IsDeleted
                    }).Where(y => y.IsDeleted == false).ToList()
                })
                                 .FirstOrDefaultAsync(x => x.IsDeleted == false && x.IndicatorId == request.indicatorId);

                if (indicators != null)
                {
                    response.data.IndicatorModel = indicators;
                }

                response.StatusCode = StaticResource.successStatusCode;
                response.Message    = StaticResource.SuccessText;
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + ex;
            }

            return(response);
        }