public ActionResult DeleteQuestion(int id) { var question = _askUC.ShowThisQuestion(id); var userQuestionVM = new UserQuestionVM { Question = question, }; return(View(userQuestionVM)); }
public IActionResult Index() { var questions = _askUC.ShowAllQuestions(); var userQuestions = new List <UserQuestionVM>(); foreach (var qst in questions) { var userQuestionVM = new UserQuestionVM { CurrentUser = _userManager.GetUserAsync(User).Result, Question = qst, QuestionAuthor = _userManager.FindByIdAsync(qst.AuthorId.ToString()).Result, }; userQuestions.Add(userQuestionVM); } return(View(userQuestions)); }
public ActionResult DeleteQuestion(int id, UserQuestionVM userQuestionVM) { try { var currentUser = _userManager.GetUserAsync(User).Result; var question = _askUC.ShowThisQuestion(id); userQuestionVM.Question = question; var questionUserId = question.AuthorId; if (currentUser.Id == userQuestionVM.Question.AuthorId) { _askUC.DeletingQuestion(currentUser.Id, userQuestionVM.Question); return(RedirectToAction(nameof(Index))); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Details(int id) { var currentUser = _userManager.GetUserAsync(User).Result; var qst = _askUC.ShowThisQuestion(id); var answers = _askUC.GetAnswersByQuestion(id); foreach (var answ in answers) { var answAuthor = _userManager.FindByIdAsync(answ.AuthorId.ToString()).Result; answ.AnswerAuthor = answAuthor; } var userQuestionVM = new UserQuestionVM { Question = qst, Answers = answers, CurrentUser = currentUser, QuestionAuthor = _userManager.FindByIdAsync(qst.AuthorId.ToString()).Result, }; return(View(userQuestionVM)); }