Пример #1
0
 private void SaveSimpleQuestion(QuestionResponseModel response, Guid userPlantId)
 {
     try
     {
         CDPSimpleChoiceAnswer data = _context.CDPSimpleChoiceAnswers.FirstOrDefault(ans => ans.PlantId == userPlantId &&
                                                                                     ans.QuestionId == response.QuestionId && ans.Year == response.Year);
         if (data != null)
         {
             data.AnswerValue = response.Value.ToString();
         }
         else
         {
             data             = new CDPSimpleChoiceAnswer();
             data.AnswerId    = Guid.NewGuid();
             data.PlantId     = userPlantId;
             data.Year        = response.Year;
             data.QuestionId  = response.QuestionId;
             data.AnswerValue = Convert.ToString(response.Value);
             _context.CDPSimpleChoiceAnswers.AddObject(data);
         }
         _context.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #2
0
        private object GetQuestionAnswerDetails(Guid userPlantId, Guid questionId, QuestionType contextName, int selectionYear)
        {
            object result = null;

            switch (contextName)
            {
            case QuestionType.Simple:
                CDPSimpleChoiceAnswer userSimpleAnswer = _context.CDPSimpleChoiceAnswers.FirstOrDefault(ans => ans.PlantId == userPlantId &&
                                                                                                        ans.QuestionId == questionId && ans.Year == selectionYear);
                if (userSimpleAnswer != null)
                {
                    result = userSimpleAnswer.AnswerValue;
                }
                break;

            case QuestionType.List:
                break;

            case QuestionType.DropDown:
                CDPSimpleChoiceAnswer userDropDownAnswer = _context.CDPSimpleChoiceAnswers.FirstOrDefault(ans => ans.PlantId == userPlantId &&
                                                                                                          ans.QuestionId == questionId && ans.Year == selectionYear);
                if (userDropDownAnswer != null)
                {
                    result = userDropDownAnswer.AnswerValue;
                }
                break;

            case QuestionType.DropDownList:
                CDPSimpleChoiceAnswer userAnswer = _context.CDPSimpleChoiceAnswers.FirstOrDefault(ans => ans.PlantId == userPlantId &&
                                                                                                  ans.QuestionId == questionId && ans.Year == selectionYear);
                if (userAnswer != null)
                {
                    result = userAnswer.AnswerValue;
                }
                break;

            case QuestionType.Option:
                CDPSimpleChoiceAnswer userOptionAnswer = _context.CDPSimpleChoiceAnswers.FirstOrDefault(ans => ans.PlantId == userPlantId &&
                                                                                                        ans.QuestionId == questionId && ans.Year == selectionYear);
                if (userOptionAnswer != null)
                {
                    result = userOptionAnswer.AnswerValue;
                }
                break;

            case QuestionType.MultipleSelectList:
                CDPSimpleChoiceAnswer userMultipleSelectListAnswer = _context.CDPSimpleChoiceAnswers.FirstOrDefault(ans => ans.PlantId == userPlantId &&
                                                                                                                    ans.QuestionId == questionId && ans.Year == selectionYear);
                if (userMultipleSelectListAnswer != null)
                {
                    result = userMultipleSelectListAnswer.AnswerValue;
                }
                break;

            case QuestionType.DateRange:
                CDPDateRangeAnswer dateRangeAns = _context.CDPDateRangeAnswers.FirstOrDefault(ans => ans.PlantId == userPlantId && ans.QuestionId == questionId && ans.Year == selectionYear);
                if (dateRangeAns != null)
                {
                    result = new DateRange()
                    {
                        StartDate = dateRangeAns.StartDate, EndDate = dateRangeAns.EndDate
                    };
                }
                break;

            case QuestionType.Date:
                break;

            case QuestionType.Boolean:
                CDPSimpleChoiceAnswer userBooleanAnswer = _context.CDPSimpleChoiceAnswers.FirstOrDefault(ans => ans.PlantId == userPlantId &&
                                                                                                         ans.QuestionId == questionId && ans.Year == selectionYear);
                if (userBooleanAnswer != null)
                {
                    result = userBooleanAnswer.AnswerValue;
                }
                break;

            case QuestionType.CDPGridResultList:
                //var gridResponse = _context.CDPTabularAnswers.FirstOrDefault(ans => ans.PlantId == userPlantId &&
                //    ans.QuestionId == questionId && ans.Year == selectionYear);
                // List<string> gridResponse
                var Answers = from tablans in _context.CDPTabularAnswers
                              where tablans.PlantId == userPlantId && tablans.QuestionId == questionId && tablans.Year == selectionYear
                              orderby tablans.Id
                              select tablans;
                //).ToList();
                List <CDPTabularAnswer> gridResponse = new List <CDPTabularAnswer>();
                foreach (var item in Answers)
                {
                    CDPTabularAnswer oCDPTabularAnswer = new CDPTabularAnswer();
                    oCDPTabularAnswer.Answer     = item.Answer;
                    oCDPTabularAnswer.Id         = item.Id;
                    oCDPTabularAnswer.PlantId    = item.PlantId;
                    oCDPTabularAnswer.QuestionId = item.QuestionId;
                    oCDPTabularAnswer.Year       = item.Year;
                    gridResponse.Add(oCDPTabularAnswer);
                }
                if (gridResponse != null)
                {
                    result = gridResponse;
                }
                break;

            case QuestionType.CDPGrid:
                //var gridResponse = _context.CDPTabularAnswers.FirstOrDefault(ans => ans.PlantId == userPlantId &&
                //    ans.QuestionId == questionId && ans.Year == selectionYear);
                // List<string> gridResponse
                var gridAnswers = from tablans in _context.CDPTabularAnswers
                                  where tablans.PlantId == userPlantId && tablans.QuestionId == questionId && tablans.Year == selectionYear
                                  orderby tablans.Id
                                  select tablans;
                //).ToList();
                List <CDPTabularAnswer> cdpgridResponse = new List <CDPTabularAnswer>();
                foreach (var item in gridAnswers)
                {
                    CDPTabularAnswer oCDPTabularAnswer = new CDPTabularAnswer();
                    oCDPTabularAnswer.Answer     = item.Answer;
                    oCDPTabularAnswer.Id         = item.Id;
                    oCDPTabularAnswer.PlantId    = item.PlantId;
                    oCDPTabularAnswer.QuestionId = item.QuestionId;
                    oCDPTabularAnswer.Year       = item.Year;
                    cdpgridResponse.Add(oCDPTabularAnswer);
                }
                if (cdpgridResponse != null)
                {
                    result = cdpgridResponse;
                }

                break;

            default:
                break;
            }
            return(result);
        }