public async Task <ActionResult> Index()
        {
            var userEmail           = User.FindFirstValue(ClaimTypes.Email);
            var userQuestionnaireId = await _patientQuestionnaireRepo.GetUserQuestionnairesIdByEmail(userEmail);

            var questionnaires         = userQuestionnaireId.Select(id => _questionnaireRepo.GetById(id).Result).ToList();
            var answeredQuestionnaires = await _userQuestionnaireAnswerRepo.GetByUserEmail(userEmail);

            var todayAnsweredQuestionnaires = answeredQuestionnaires.Where(q => q.AnswerDate.Value.Date == DateTime.Today).ToList();
            var idToRemove = questionnaires.Where(questionnaire => todayAnsweredQuestionnaires.Count(q => q.QuestionnaireId == questionnaire.Id) >= 5).Select(questionnaire => questionnaire.Id).ToList();

            foreach (var id in idToRemove)
            {
                questionnaires.Remove(questionnaires.FirstOrDefault(q => q.Id == id));
            }

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

            return(View(model));
        }
        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("~/"));
        }