public async Task <IActionResult> OnPost(int expertId) { Expert = expertData.GetById(expertId); if (Expert == null) { return(RedirectToPage("./NotFound")); } userProfile = accountData.GetById(Expert.userId); userProfile.IsExpert = false; accountData.Update(userProfile); foreach (var answer in Expert.Answers) { answerData.Delete(answer); } await answerData.Commit(); expertData.Delete(Expert); if (await expertData.Commit()) { if (await accountData.Commit()) { TempData["Message"] = $"Expert {Expert.firstName} {Expert.lastName} Deleted"; return(RedirectToPage("./ManageExperts")); } } return(RedirectToPage("./NotFound")); }
public async Task <IActionResult> OnPost(int questionId) { Question = questionData.GetById(questionId); if (Question == null) { return(RedirectToPage("./NotFound")); } if (Question.answered == true) { answerData.Delete(Question.Answer); await answerData.Commit(); } questionData.Delete(Question); await answerData.Commit(); TempData["Message"] = $"Question Deleted"; return(RedirectToPage("./QuestionList", new { questionTypeId = Question.typeId })); }
public async Task <IActionResult> OnPost() { if (!ModelState.IsValid) { return(Page()); } answerData.Update(Answer); if (await answerData.Commit()) { TempData["Message"] = $"Answer Updated"; return(RedirectToPage("./QuestionDetail", new { questionId = Answer.questionId })); } return(RedirectToPage("./NotFound")); }
public async Task <IActionResult> OnPost() { Question = questionData.GetById(Answer.questionId); if (!ModelState.IsValid) { return(Page()); } var user = await userManager.GetUserAsync(User); Expert = expertData.GetByUserId(user.Id); Question.answered = true; questionData.Update(Question); Answer.expertId = Expert.id; answerData.Add(Answer); if (await answerData.Commit()) { TempData["Message"] = $"Answer Added"; return(RedirectToPage("./QuestionDetail", new { questionId = Answer.questionId })); } return(RedirectToPage("./NotFound")); }