コード例 #1
0
        public IActionResult EditStackOverflowQuestionForm(StackOverflowQuestionModel model, int Id)
        {
            StackOverflowQuestion question = _context.StackOverflowQuestions.FirstOrDefault(a => a.Id == Id);

            question.Question = model.Question;

            _context.StackOverflowQuestions.Update(question);
            _context.SaveChanges();
            return(RedirectToAction("StackOverflowQuestions"));
        }
コード例 #2
0
        public async Task <IActionResult> StackOverflowQuestionForm(StackOverflowQuestionModel model)
        {
            try
            {
                string userName = User.Identity.Name;
                StackOverflowQuestion question = new StackOverflowQuestion()
                {
                    UserName = userName,
                    Question = model.Question
                };

                await _context.StackOverflowQuestions.AddAsync(question);

                await _context.SaveChangesAsync();

                return(RedirectToAction("StackOverflowQuestions"));
            }
            catch (System.Exception)
            {
                return(RedirectToAction("StackOverflowQuestions"));
            }
        }