예제 #1
0
        public IActionResult EditStackOverflowAnswerForm(StackOverflowAnswerModel model, int Id)
        {
            StackOverflowAnswer answer = _context.StackOverflowAnswers.FirstOrDefault(a => a.Id == Id);

            answer.Answer = model.Answer;

            _context.StackOverflowAnswers.Update(answer);
            _context.SaveChanges();
            return(RedirectToAction($"StackOverflowAnswers", new { Id = answer.QuestionId }));
        }
예제 #2
0
        public async Task <IActionResult> StackOverflowAnswerForm(int Id, StackOverflowAnswerModel model)
        {
            try
            {
                string userName            = User.Identity.Name;
                StackOverflowAnswer answer = new StackOverflowAnswer()
                {
                    QuestionId = Id,
                    UserName   = userName,
                    Answer     = model.Answer
                };

                await _context.StackOverflowAnswers.AddAsync(answer);

                await _context.SaveChangesAsync();

                return(RedirectToAction($"StackOverflowAnswers", new { Id = Id }));
            }
            catch (Exception e)
            {
                return(View());
            }
        }