public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } tAnswer = await _context.tAnswer.SingleOrDefaultAsync(m => m.answer_id == id); if (tAnswer == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } tAnswer = await _context.tAnswer.FindAsync(id); if (tAnswer != null) { _context.tAnswer.Remove(tAnswer); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { tProgramQuestion pquestion = new tProgramQuestion(); if (!ModelState.IsValid) { return(Page()); } tQuestion.approval_status = "Approved"; tQuestion.approved_by = "System"; tQuestion.approved_date = DateTime.Now; tQuestion.create_by = "System"; tQuestion.create_date = DateTime.Now; tQuestion.edit_by = "System"; tQuestion.edit_date = DateTime.Now; _context.tQuestion.Add(tQuestion); _context.SaveChanges(); // id after insert question int id = tQuestion.question_id; pquestion.question_id = id; pquestion.program_id = pq.program_id; _context.tProgramQuestion.Add(pquestion); await _context.SaveChangesAsync(); for (int i = 0; i < 5; i++) { tAnswer a = new tAnswer(); a.answer_detail = i.ToString();; a.create_by = "System"; a.create_date = DateTime.Now; a.edit_by = "System"; a.edit_date = DateTime.Now; a.question_id = id; a.score = i; _context.tAnswer.Add(a); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }