示例#1
0
        public ActionResult DeleteQuestion(int id)
        {
            var question       = _askUC.ShowThisQuestion(id);
            var userQuestionVM = new UserQuestionVM
            {
                Question = question,
            };

            return(View(userQuestionVM));
        }
示例#2
0
        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));
        }
示例#3
0
 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());
     }
 }
示例#4
0
        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));
        }