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

            try
            {
                ProjectMonitoringReviewDetail projectMonitoringReviewDetail = new ProjectMonitoringReviewDetail();
                projectMonitoringReviewDetail.ActivityId      = request.ActivityId;
                projectMonitoringReviewDetail.CreatedById     = request.CreatedById;
                projectMonitoringReviewDetail.ProjectId       = request.ProjectId;
                projectMonitoringReviewDetail.MonitoringDate  = request.MonitoringDate;
                projectMonitoringReviewDetail.CreatedDate     = request.CreatedDate;
                projectMonitoringReviewDetail.IsDeleted       = false;
                projectMonitoringReviewDetail.NegativePoints  = request.NegativePoints;
                projectMonitoringReviewDetail.PostivePoints   = request.PositivePoints;
                projectMonitoringReviewDetail.Recommendations = request.Recommendations;
                projectMonitoringReviewDetail.Remarks         = request.Remarks;

                await _dbContext.ProjectMonitoringReviewDetail.AddAsync(projectMonitoringReviewDetail);

                await _dbContext.SaveChangesAsync();

                foreach (var item in request.MonitoringReviewModel)
                {
                    ProjectMonitoringIndicatorDetail monitoringIndicatorDetail = new ProjectMonitoringIndicatorDetail();
                    monitoringIndicatorDetail.CreatedById = request.CreatedById;
                    monitoringIndicatorDetail.CreatedDate = request.CreatedDate;
                    monitoringIndicatorDetail.IsDeleted   = false;
                    monitoringIndicatorDetail.ProjectMonitoringReviewId = projectMonitoringReviewDetail.ProjectMonitoringReviewId;
                    monitoringIndicatorDetail.ProjectIndicatorId        = item.ProjectIndicatorId;

                    await _dbContext.ProjectMonitoringIndicatorDetail.AddAsync(monitoringIndicatorDetail);

                    await _dbContext.SaveChangesAsync();

                    foreach (var obj in item.IndicatorQuestions)
                    {
                        ProjectMonitoringIndicatorQuestions monitoringQuestions = new ProjectMonitoringIndicatorQuestions();
                        monitoringQuestions.IsDeleted             = false;
                        monitoringQuestions.CreatedDate           = request.CreatedDate;
                        monitoringQuestions.CreatedById           = request.CreatedById;
                        monitoringQuestions.QuestionId            = obj.QuestionId;
                        monitoringQuestions.Verification          = obj.Verification;
                        monitoringQuestions.VerificationId        = obj.VerificationId;
                        monitoringQuestions.MonitoringIndicatorId = monitoringIndicatorDetail.MonitoringIndicatorId;
                        monitoringQuestions.Score = obj.Score;

                        await _dbContext.ProjectMonitoringIndicatorQuestions.AddAsync(monitoringQuestions);

                        await _dbContext.SaveChangesAsync();
                    }
                }
                response.StatusCode = StaticResource.successStatusCode;
                response.Message    = "Success";
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + ex.Message;
            }
            return(response);
        }
예제 #2
0
        public async Task <ApiResponse> Handle(EditProjectMonitoringByMonitoringIdCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                var monitoring = await _dbContext.ProjectMonitoringReviewDetail
                                 .FirstOrDefaultAsync(x => x.IsDeleted == false && x.ProjectMonitoringReviewId == request.ProjectMonitoringReviewId);

                // monitoring.ActivityId = request.ActivityId;
                monitoring.ModifiedById = request.ModifiedById;
                // monitoring.ProjectId = request.ProjectId;
                monitoring.MonitoringDate  = request.MonitoringDate;
                monitoring.ModifiedDate    = request.ModifiedDate;
                monitoring.IsDeleted       = false;
                monitoring.NegativePoints  = request.NegativePoints;
                monitoring.PostivePoints   = request.PositivePoints;
                monitoring.Recommendations = request.Recommendations;
                monitoring.Remarks         = request.Remarks;

                _dbContext.ProjectMonitoringReviewDetail.Update(monitoring);
                await _dbContext.SaveChangesAsync();

                List <ProjectMonitoringIndicatorDetail> indicators = await _dbContext.ProjectMonitoringIndicatorDetail.Where(x => x.IsDeleted == false && x.ProjectMonitoringReviewId == monitoring.ProjectMonitoringReviewId).ToListAsync();

                indicators.ForEach(x => x.IsDeleted = true);

                _dbContext.ProjectMonitoringIndicatorDetail.UpdateRange(indicators);
                await _dbContext.SaveChangesAsync();

                foreach (var item in request.MonitoringReviewModel)
                {
                    ProjectMonitoringIndicatorDetail monitoringIndicatorDetail = new ProjectMonitoringIndicatorDetail();

                    if (item.MonitoringIndicatorId == null)
                    {
                        monitoringIndicatorDetail.CreatedById = request.CreatedById;
                        monitoringIndicatorDetail.CreatedDate = request.CreatedDate;
                        monitoringIndicatorDetail.IsDeleted   = false;
                        monitoringIndicatorDetail.ProjectMonitoringReviewId = monitoring.ProjectMonitoringReviewId;
                        monitoringIndicatorDetail.ProjectIndicatorId        = item.ProjectIndicatorId;

                        await _dbContext.ProjectMonitoringIndicatorDetail.AddAsync(monitoringIndicatorDetail);

                        await _dbContext.SaveChangesAsync();
                    }
                    else
                    {
                        monitoringIndicatorDetail = await _dbContext.ProjectMonitoringIndicatorDetail
                                                    .FirstOrDefaultAsync(x => x.MonitoringIndicatorId == item.MonitoringIndicatorId);

                        monitoringIndicatorDetail.ModifiedById       = request.ModifiedById;
                        monitoringIndicatorDetail.IsDeleted          = false;
                        monitoringIndicatorDetail.ModifiedDate       = request.ModifiedDate;
                        monitoringIndicatorDetail.ProjectIndicatorId = item.ProjectIndicatorId;
                        _dbContext.ProjectMonitoringIndicatorDetail.Update(monitoringIndicatorDetail);
                        await _dbContext.SaveChangesAsync();
                    }

                    if (item.IndicatorQuestions.Any())
                    {
                        foreach (var obj in item.IndicatorQuestions)
                        {
                            ProjectMonitoringIndicatorQuestions monitoringQuestions = new ProjectMonitoringIndicatorQuestions();

                            if (obj.MonitoringIndicatorQuestionId == null)
                            {
                                monitoringQuestions.IsDeleted             = false;
                                monitoringQuestions.CreatedDate           = request.CreatedDate;
                                monitoringQuestions.CreatedById           = request.CreatedById;
                                monitoringQuestions.QuestionId            = obj.QuestionId;
                                monitoringQuestions.Verification          = obj.Verification;
                                monitoringQuestions.VerificationId        = obj.VerificationId;
                                monitoringQuestions.MonitoringIndicatorId = monitoringIndicatorDetail.MonitoringIndicatorId;
                                monitoringQuestions.Score = obj.Score;
                                await _dbContext.ProjectMonitoringIndicatorQuestions.AddAsync(monitoringQuestions);

                                await _dbContext.SaveChangesAsync();
                            }
                            else
                            {
                                monitoringQuestions = await _dbContext.ProjectMonitoringIndicatorQuestions
                                                      .FirstOrDefaultAsync(x => x.IsDeleted == false && x.Id == obj.MonitoringIndicatorQuestionId);


                                monitoringQuestions.ModifiedDate   = request.ModifiedDate;
                                monitoringQuestions.ModifiedById   = request.ModifiedById;
                                monitoringQuestions.QuestionId     = obj.QuestionId;
                                monitoringQuestions.Score          = obj.Score;
                                monitoringQuestions.Verification   = obj.Verification;
                                monitoringQuestions.VerificationId = obj.VerificationId;
                                _dbContext.ProjectMonitoringIndicatorQuestions.Update(monitoringQuestions);
                                await _dbContext.SaveChangesAsync();
                            }
                        }
                    }
                }

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