Example #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"));
        }
Example #2
0
        public IActionResult EditStackOverflowQuestionForm(int Id)
        {
            ViewBag.Id = Id;

            var question = _context.StackOverflowQuestions.FirstOrDefault(p => p.Id == Id);
            var model    = new StackOverflowQuestionModel()
            {
                Question = question.Question
            };

            return(View(model));
        }
Example #3
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"));
            }
        }