public async Task <IActionResult> OnPostAsync(int?id) { Answer = await _context.Answer .Include(a => a.Question).FirstOrDefaultAsync(m => m.AnswerID == id); if (!ModelState.IsValid) { PopulateQuestionsDropDownList(_context, Answer.QuestionID); return(Page()); } var answerToUpdate = await _context.Answer.FindAsync(id); if (await TryUpdateModelAsync( answerToUpdate, "answer", a => a.Body, a => a.QuestionID)) { await _context.SaveChangesAsync(); return(RedirectToPage("../Questions/Details", new { id = answerToUpdate.QuestionID })); } PopulateQuestionsDropDownList(_context, answerToUpdate.QuestionID); return(Page()); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var currUser = await _userManager.GetUserAsync(User); Topic.UserId = currUser.Id; _context.Attach(Topic).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TopicExists(Topic.TopicID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var currUser = await _userManager.GetUserAsync(User); Topic.UserId = currUser.Id; _context.Topic.Add(Topic); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Topic = await _context.Topic.FindAsync(id); if (Topic != null) { _context.Topic.Remove(Topic); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Answer = await _context.Answer.FindAsync(id); if (Answer != null) { _context.Answer.Remove(Answer); await _context.SaveChangesAsync(); } return(RedirectToPage("../Questions/Details", new { id = Answer.QuestionID })); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Question = await _context.Question .AsNoTracking() .FirstOrDefaultAsync(m => m.QuestionID == id); if (Question != null) { _context.Question.Remove(Question); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (!ModelState.IsValid) { PopulateTopicsDropDownList(_context, Question.TopicID); return(Page()); } var questionToUpdate = await _context.Question.FindAsync(id); if (await TryUpdateModelAsync( questionToUpdate, "question", q => q.Body, q => q.TopicID)) { await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } PopulateTopicsDropDownList(_context, questionToUpdate.TopicID); return(Page()); }
public async Task <IActionResult> OnPostAsync(int?topicId) { if (!ModelState.IsValid) { PopulateTopicsDropDownList(_context, topicId); return(Page()); } var emptyQuestion = new Question(); if (await TryUpdateModelAsync( emptyQuestion, "question", s => s.QuestionID, s => s.TopicID, s => s.Body, s => s.Topic)) { _context.Question.Add(emptyQuestion); await _context.SaveChangesAsync(); return(RedirectToPage("../Questions/Details", new { id = emptyQuestion.QuestionID })); } PopulateTopicsDropDownList(_context, emptyQuestion.QuestionID); return(Page()); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { PopulateQuestionsDropDownList(_context); return(Page()); } var emptyAnswer = new Answer(); if (await TryUpdateModelAsync( emptyAnswer, "answer", s => s.AnswerID, s => s.QuestionID, s => s.Body, s => s.Question)) { _context.Answer.Add(emptyAnswer); await _context.SaveChangesAsync(); return(RedirectToPage("../Questions/Details", new { id = emptyAnswer.QuestionID })); } PopulateQuestionsDropDownList(_context, emptyAnswer.AnswerID); return(Page()); }