public async Task <ActionResult> RemoveQuestionnaire(int id) { var questions = await _questionRepo.GetQuestionsByQuestionnaireId(id); foreach (var question in questions) { var answers = await _answerRepo.GetAnswersByQuestionId(question.Id); foreach (var answer in answers) { await _answerRepo.Delete(answer); } await _questionRepo.Delete(question); } var patientsQuestionnaires = _patientQuestionnaireRepo.GetPatientQuestionnairesByQuestionnaireId(id).Result; foreach (var patientQuestionnaire in patientsQuestionnaires) { await _patientQuestionnaireRepo.Delete(patientQuestionnaire); } var questionnaire = await _questionnaireRepo.GetById(id); await _questionnaireRepo.Delete(questionnaire); return(RedirectToAction(nameof(Index))); }
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("~/")); }
public async Task <ActionResult> RemoveQuestionnaireFromPatient(int id, string email) { var patientQuestionnaire = await _patientQuestionnaireRepo.GetByIdAndUserEmail(id, email); await _patientQuestionnaireRepo.Delete(patientQuestionnaire); var userAnswers = await _userAnswerRepo.GetUserAnswersByUserEmail(email); var answersToSelectedQuestionnaire = userAnswers.Where(answer => _questionRepo.GetById(answer.QuestionId).Result.QuestionnaireId == id).ToList(); var questionnaireAnswered = _userQuestionnaireAnswerRepo.GetByUserEmailAndQuestionnaireId(email, id).Result; foreach (var userAnswer in answersToSelectedQuestionnaire) { await _userAnswerRepo.Delete(userAnswer); } foreach (var questionnaire in questionnaireAnswered) { await _userQuestionnaireAnswerRepo.Delete(questionnaire); } return(RedirectToAction("ManagePatientQuestionnaires", new { id = email })); }