Exemple #1
0
        public async Task <ActionResult> ManageQuestions(int id)
        {
            var questionnaire = await _questionnaireRepo.GetById(id);

            var questions = await _questionRepo.GetQuestionsByQuestionnaireId(id);

            var model = new QuestionnaireViewModel
            {
                Id     = id,
                Name   = questionnaire.Name,
                Fields = new List <FieldViewModel>()
            };

            var i = 0;

            foreach (var question in questions)
            {
                var answers = await _answerRepo.GetAnswersByQuestionId(question.Id);

                var answerViewModels = answers.Select(answer => new AnswerViewModel {
                    Content = answer.Content, Value = answer.Value
                }).ToList();

                model.Fields.Add(new FieldViewModel
                {
                    Count      = i,
                    Question   = question.Contents,
                    QuestionId = question.Id,
                    Answers    = answerViewModels
                });
                i++;
            }

            return(View(model));
        }
        public async Task <ActionResult> FillQuestionnaire(int id)
        {
            var userEmail = User.FindFirstValue(ClaimTypes.Email);
            var patientQuestionnairesIds = await _patientQuestionnaireRepo.GetUserQuestionnairesIdByEmail(userEmail);

            if (!patientQuestionnairesIds.Contains(id))
            {
                return(RedirectToAction(nameof(Index)));
            }

            var answeredQuestionnaires = await _userQuestionnaireAnswerRepo.GetByUserEmail(userEmail);

            if (answeredQuestionnaires.Where(q => q.AnswerDate.Value.Date == DateTime.Today && q.QuestionnaireId == id).ToList().Count >= 5)
            {
                return(RedirectToAction(nameof(Index)));
            }

            var questionnaire = await _questionnaireRepo.GetById(id);

            var questions = await _questionRepo.GetQuestionsByQuestionnaireId(id);

            var model = new QuestionnaireViewModel
            {
                Name   = questionnaire.Name,
                Fields = new List <FieldViewModel>()
            };

            var i = 0;

            foreach (var question in questions)
            {
                var answers = await _answerRepo.GetAnswersByQuestionId(question.Id);

                var answerViewModels = answers.Select(answer => new AnswerViewModel {
                    Content = answer.Content, Value = answer.Value
                }).ToList();

                model.Fields.Add(new FieldViewModel
                {
                    Count      = i,
                    Question   = question.Contents,
                    QuestionId = question.Id,
                    Answers    = answerViewModels
                });
                i++;
            }

            return(View(model));
        }