// To protect from overposting attacks, enable the specific properties you want to bind to. // For more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Group).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GroupExists(Group.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int id) { if (!ModelState.IsValid) { return(Page()); } //Lesson = par; var curentUser = await _userManager.GetUserAsync(HttpContext.User); if (curentUser == null) { return(NotFound()); } Student = await _context.Students.Include(x => x.Cathedra).FirstOrDefaultAsync(st => st.User == curentUser); if (Student == null) { return(NotFound()); } Lesson = await _context.Lessons .Include(x => x.Questions).ThenInclude(x => x.Answers) .Include(x => x.Teacher) .AsSplitQuery() .FirstOrDefaultAsync(x => x.Id == id); var lastTest = await _context.TestResults.FirstOrDefaultAsync(tr => tr.Answerer == Student && tr.Topic.Id == Lesson.Id); if (lastTest != null) { return(RedirectToPage("./Pass", new { id = id.ToString(), q = Lesson.Questions.First().Id.ToString() })); } var testResult = new TestResult() { Answerer = Student, Reviewer = Lesson.Teacher, PassDate = DateTime.Now, TopicId = Lesson.Id, }; testResult.Answers = Lesson.Questions.SelectMany( q => q.Answers.Select(a => new TestAnswer() { AnswerId = a.Id, QuestionId = q.Id, TestResult = testResult, UserAnswer = false, } ).ToList() ).ToList(); _context.TestResults.Add(testResult); await _context.SaveChangesAsync(); var q = testResult.Answers.First().Question.Id.ToString(); return(RedirectToPage("./Pass", new { id = id.ToString(), q })); }
// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Cathedras.Add(Cathedra); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Group = await _context.Groups.FindAsync(id); if (Group != null) { _context.Groups.Remove(Group); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Lesson = await _context.Lessons.FindAsync(id); if (Lesson != null) { await _context.TestResults.Include(x => x.Answers).Where(tr => tr.Topic == Lesson).ToListAsync(); await _context.Questions.Include(x => x.Answers).Where(a => a.Lesson == Lesson).ToListAsync(); _context.Lessons.Remove(Lesson); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }