public async Task <IActionResult> OnPostAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            RequirePassword = await _userManager.HasPasswordAsync(user);

            if (RequirePassword)
            {
                if (!await _userManager.CheckPasswordAsync(user, Input.Password))
                {
                    ModelState.AddModelError(string.Empty, "Incorrect password.");
                    return(Page());
                }
            }

            var patientQuestionnaires =
                _patientQuestionnaireRepo.GetPatientQuestionnairesByEmail(User.FindFirstValue(ClaimTypes.Email)).Result;

            foreach (var patientQuestionnaire in patientQuestionnaires)
            {
                _patientQuestionnaireRepo.Delete(patientQuestionnaire).Wait();
            }

            var userEmail             = User.FindFirstValue(ClaimTypes.Email);
            var userAnswers           = _userAnswerRepo.GetUserAnswersByUserEmail(userEmail).Result;
            var questionnaireAnswered = _userQuestionnaireAnswerRepo.GetByUserEmail(userEmail).Result;

            foreach (var userAnswer in userAnswers)
            {
                _userAnswerRepo.Delete(userAnswer).Wait();
            }

            foreach (var questionnaire in questionnaireAnswered)
            {
                _userQuestionnaireAnswerRepo.Delete(questionnaire).Wait();
            }

            var result = await _userManager.DeleteAsync(user);


            var userId = await _userManager.GetUserIdAsync(user);

            if (!result.Succeeded)
            {
                throw new InvalidOperationException($"Unexpected error occurred deleting user with ID '{userId}'.");
            }

            await _signInManager.SignOutAsync();

            _logger.LogInformation("User with ID '{UserId}' deleted themselves.", userId);

            return(Redirect("~/"));
        }
Example #2
0
        public async Task <ActionResult> PatientQuestionnaires(string id)
        {
            var patientQuestionnaires = await _patientQuestionnaireRepo.GetPatientQuestionnairesByEmail(id);

            var patientQuestionnaireViewModels = patientQuestionnaires.Select(patientQuestionnaire =>
                                                                              new PatientQuestionnaireViewModel
            {
                PatientEmail      = id,
                QuestionnaireId   = patientQuestionnaire.QuestionnaireId,
                QuestionnaireName = _questionnaireRepo.GetById(patientQuestionnaire.QuestionnaireId).Result.Name
            }).ToList();

            var model = new PatientQuestionnaireManagerViewModel
            {
                PatientEmail          = id,
                PatientQuestionnaires = patientQuestionnaireViewModels
            };

            return(View(model));
        }
Example #3
0
        public async Task <ActionResult> ManagePatientQuestionnaires(string id)
        {
            var patientQuestionnaires = await _patientQuestionnaireRepo.GetPatientQuestionnairesByEmail(id);

            var patientQuestionnaireViewModels = patientQuestionnaires.Select(patientQuestionnaire =>
                                                                              new PatientQuestionnaireViewModel {
                PatientEmail    = patientQuestionnaire.PatientEmail,
                QuestionnaireId = patientQuestionnaire.QuestionnaireId
            }).ToList();

            var questionnaires = await _questionnaireRepo.GetAll();

            var questionnaireViewModels = questionnaires.Select(questionnaire =>
                                                                new QuestionnaireViewModel {
                Fields = null,
                Id     = questionnaire.Id,
                Name   = questionnaire.Name
            }).ToList();

            foreach (var item in patientQuestionnaireViewModels)
            {
                item.QuestionnaireName = _questionnaireRepo.GetById(item.QuestionnaireId).Result.Name;
                if (questionnaireViewModels.Any(x =>
                                                x.Id == item.QuestionnaireId))
                {
                    questionnaireViewModels.Remove(
                        questionnaireViewModels.FirstOrDefault(q =>
                                                               q.Id == item.QuestionnaireId));
                }
            }

            var model = new PatientQuestionnaireManagerViewModel
            {
                PatientEmail          = id,
                PatientQuestionnaires = patientQuestionnaireViewModels,
                Questionnaires        = questionnaireViewModels
            };

            return(View(model));
        }