public async Task <IActionResult> OnPostAsync(int id) { if (!ModelState.IsValid) { return(Page()); } try { Enrollment newRecord = new Enrollment(); newRecord.CourseId = id; newRecord.StudentId = Enrollment.StudentId; _context.Enrollment.Add(newRecord); await _context.SaveChangesAsync(); return(RedirectToPage("/Courses/Index")); } catch (Exception) { ViewData["error"] = ERROR_MESSAGE; return(Page()); } }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Course).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CourseExists(Course.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Student.Add(Student); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Course = await _context.Course.FindAsync(id); if (Course != null) { _context.Course.Remove(Course); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }