public void SaveQuestionResponse(Guid questionId, string answer, string questionType, int year)
        {
            try
            {
                if (_log.IsInfoEnabled)
                {
                    _log.Info("Calling Index method of GetQuestionView");
                }
                QuestionResponseModel response = new QuestionResponseModel();
                response.QuestionId   = questionId;
                response.Value        = answer;
                response.Year         = year;
                response.QuestionType = (QuestionType)Enum.Parse(typeof(QuestionType), questionType);

                if (CurrentUser.PlantId == null)
                {
                    throw new InvalidOperationException("User does not belong to any Plant.");
                }

                oQuestionnaireService.SaveQuestionResponse(response, CurrentUser.PlantId ?? Guid.Empty);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
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;
     }
 }
Beispiel #3
0
        private void SaveDateRangeQuestion(QuestionResponseModel response, Guid userPlantId)
        {
            try
            {
                CDPDateRangeAnswer data = _context.CDPDateRangeAnswers.FirstOrDefault(ans => ans.PlantId == userPlantId &&
                                                                                      ans.QuestionId.Equals(response.QuestionId) && ans.Year == response.Year);
                string[] date = response.Value.ToString().Split('s');

                if (data != null)
                {
                    data.StartDate = Convert.ToDateTime(date[0]);
                    data.EndDate   = Convert.ToDateTime(date[1]);
                }
                else
                {
                    data            = new CDPDateRangeAnswer();
                    data.AnswerId   = Guid.NewGuid();
                    data.PlantId    = userPlantId;
                    data.Year       = response.Year;
                    data.QuestionId = response.QuestionId;
                    data.StartDate  = Convert.ToDateTime(date[0]);
                    data.EndDate    = Convert.ToDateTime(date[1]);
                    _context.CDPDateRangeAnswers.AddObject(data);
                }
                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #4
0
 public void QuestionBcTests_UpdateNonExistingQuestion()
 {
     var question = new QuestionResponseModel
     {
         Id = 0
     };
     var updated = questionBc.UpdateQuestion(question);
 }
Beispiel #5
0
        public void SaveQuestionResponse(QuestionResponseModel response, Guid userPlantId)
        {
            try
            {
                switch (response.QuestionType)
                {
                case QuestionType.Simple:
                    SaveSimpleQuestion(response, userPlantId);
                    break;

                case QuestionType.List:
                    break;

                case QuestionType.DropDown:
                    SaveSimpleQuestion(response, userPlantId);
                    break;

                case QuestionType.DropDownList:
                    SaveDropDown(response, userPlantId);
                    break;

                case QuestionType.Option:
                    SaveOptionQuestion(response, userPlantId);
                    break;

                case QuestionType.OptionList:
                    break;

                case QuestionType.DateRange:
                    SaveDateRangeQuestion(response, userPlantId);
                    break;

                case QuestionType.Date:
                    break;

                case QuestionType.Boolean:
                    SaveBooleanQuestion(response, userPlantId);
                    break;

                case QuestionType.CDPGrid:
                    break;

                case QuestionType.MultipleSelectList:
                    SaveMultipleSelectListQuestion(response, userPlantId);
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #6
0
        public async Task <IHttpActionResult> UpdateQuestion(
            long id,
            QuestionResponseModel model,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            return(await ExecuteAsync <IHttpActionResult>(() =>
            {
                if (!ModelState.IsValid)
                {
                    throw new BlissException(CommonExceptionResources.AllFieldsMandatory);
                }

                return Ok(questionBc.UpdateQuestion(model));
            }, cancellationToken));
        }
        public QuestionManagerTest()
        {
            questionResponse = new QuestionResponseModel
            {
                DifficultyLevelId = "ce705f44-07e0-45c6-b51d-3b1af6256848",
                ShuffleOptions    = true,
                ScoreValue        = 10,
                SubjectId         = "f4eb2f0a-ef7f-4d16-abc2-dfabf6b660c0",
                QuestionType      = "",
                Text    = "Test Question",
                Id      = "ce705f44-07e0-45c6-b51d-3b1af6256848",
                Options = new List <QuestionOption> {
                    new QuestionOption {
                        IsAnswer = true, Text = "Option text"
                    },
                    new QuestionOption {
                        IsAnswer = true, Text = "Option text"
                    }
                }, DifficultyLevel = "Easy", Subject = "Mathematics",
            };


            _questionRepoMock = new Mock <IQuestionRepository>(MockBehavior.Strict);

            _questionValidator = new Mock <IQuestionValidator>(MockBehavior.Strict);

            validatorMessage = "Is Valid";

            _questionValidator.Setup(u => u.ValidateNumberOfOptions(It.IsAny <QuestionRequestModel>(), out validatorMessage))
            .Returns(true);

            _questionValidator.Setup(u => u.ValidateQuestion(It.IsAny <QuestionRequestModel>(), out validatorMessage))
            .Returns(true);

            _questionValidator.Setup(u => u.ValidateQuestionOptions(It.IsAny <QuestionRequestModel>(), out validatorMessage))
            .Returns(true);

            _questionValidator.Setup(u => u.ValidateQuestionType(It.IsAny <QuestionRequestModel>(), out validatorMessage))
            .Returns(true);

            _questionRepoMock.Setup(u => u.GetQuestionAsync(questionResponse.Id))
            .Returns(Task.FromResult(questionResponse));


            _questionManager = new QuestionManager(_questionRepoMock.Object, _questionValidator.Object);
        }
Beispiel #8
0
        private void MapQuestion(Question dbQuestion, QuestionResponseModel model)
        {
            dbQuestion.QuestionDescription = model.Question;
            dbQuestion.ImageUrl            = model.ImageUrl;
            dbQuestion.ThumbUrl            = model.ThumbUrl;
            dbQuestion.PublishedAt         = DateTime.Now;

            foreach (var choice in model.Choices)
            {
                questionChoiceRepo.Add(new QuestionChoice
                {
                    QuestionId = dbQuestion.Id,
                    Name       = choice.Name,
                    Votes      = choice.Votes
                });
            }
        }
Beispiel #9
0
        public QuestionResponseModel GetQuestionResponse(Guid questionId, Guid userPlantId, int selectedYear)
        {
            CDPQuestion     question     = _context.CDPQuestions.FirstOrDefault(q => q.QId == questionId);
            CDPQuestionType questionType = _context.CDPQuestionTypes.FirstOrDefault(type => type.Id == question.QuestionType);

            //CDPQuestionValidation validate = _context.CDPQuestionValidations.FirstOrDefault(m => m.QuestionId == questionId);
            //CDPValidationType validationType = _context.CDPValidationTypes.FirstOrDefault(m => m.Id == validate.ValidationId);

            QuestionResponseModel result = new QuestionResponseModel();

            result.QuestionType = (QuestionType)Enum.Parse(typeof(QuestionType), questionType.Type);
            result.CDPId        = question.QuestionId;
            result.Caption      = question.Title;
            result.QuestionText = question.QuestionText;
            result.Value        = GetQuestionAnswerDetails(userPlantId, questionId, result.QuestionType, selectedYear);
            if (questionType.Type != "Simple")
            {
                result.OptionList = GetOptionList(questionId);
            }
            result.QuestionId = questionId;
            result.Year       = DateTime.Now.Year;
            result.IsAnswerResponseAllowed = question.IsApplicable ?? true;
            result.Validations             = (from validation in _context.CDPQuestionValidations.ToList()
                                              join type in _context.CDPValidationTypes.ToList() on validation.ValidationId equals type.Id
                                              where (validation.QuestionId == questionId)
                                              select new Validation
            {
                ValidationValue = validation.Value,
                ValidationType = ParseValidationType(type.ValidationType)
            }).ToList();

            Validation defaultValueResutlt = null;

            if (result.Validations != null && (result.Value == null || string.IsNullOrEmpty(Convert.ToString(result.Value))))
            {
                defaultValueResutlt = result.Validations.FirstOrDefault(v => v.ValidationType == ValidationType.DefaultValue);
                if (defaultValueResutlt != null)
                {
                    result.Value = defaultValueResutlt.ValidationValue;
                }
            }
            return(result);
        }
Beispiel #10
0
        public QuestionResponseModel UpdateQuestion(QuestionResponseModel model)
        {
            var dbQuestion = questionRepo.GetById(model.Id);

            if (dbQuestion == null)
            {
                throw new BlissException(CommonExceptionResources.QuestionNotFound);
            }

            // Delete old choices
            questionChoiceRepo.DeleteByQuestionId(dbQuestion.Id);
            questionRepo.Save();

            questionRepo.TrackExisting(dbQuestion);

            // Add new choices
            MapQuestion(dbQuestion, model);
            questionRepo.Save();

            model.PublishedAt = dbQuestion.PublishedAt;
            return(model);
        }