Beispiel #1
0
        public async Task <IActionResult> Create(Question question)
        {
            var userId      = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            question.User = currentUser;
            _db.Questions.Add(question);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public async Task <IActionResult> Create(int QuestionId, string content)
        {
            var comment = new Comment();

            comment.content = content;
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            comment.Question = _db.Questions
                               .FirstOrDefault(question => question.id == QuestionId);
            comment.user = currentUser;
            _db.Comments.Add(comment);
            _db.SaveChanges();
            return(RedirectToAction("Index", "Account", null));
        }