public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Student).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(Student.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id, string[] selectedCourses) { if (!ModelState.IsValid) { return(Page()); } var instructorToUpdate = await _context.Instructor .Include(i => i.OfficeAssignment) .Include(i => i.CourseAssignments) .ThenInclude(i => i.Course) .FirstOrDefaultAsync(s => s.ID == id); if (await TryUpdateModelAsync <Instructor>( instructorToUpdate, "Instructor", i => i.FirstMidName, i => i.LastName, i => i.HireDate, i => i.OfficeAssignment)) { if (String.IsNullOrWhiteSpace( instructorToUpdate.OfficeAssignment?.Location)) { instructorToUpdate.OfficeAssignment = null; } UpdateInstructorCourses(_context, selectedCourses, instructorToUpdate); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } UpdateInstructorCourses(_context, selectedCourses, instructorToUpdate); PopulateAssignedCourseData(_context, instructorToUpdate); return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } var student = await _context.Student .AsNoTracking() .FirstOrDefaultAsync(m => m.ID == id); if (student == null) { return(NotFound()); } try { _context.Student.Remove(student); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log.) return(RedirectToAction("./Delete", new { id, saveChangesError = true })); } }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Course.Add(Course); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var emptyStudent = new Student(); if (await TryUpdateModelAsync <Student>( emptyStudent, "student", // Prefix for form value. s => s.FirstMidName, s => s.LastName, s => s.EnrollmentDate)) { _context.Student.Add(emptyStudent); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } return(null); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Student = await _context.Student.FindAsync(id); if (Student != null) { _context.Student.Remove(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")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } InstructorIndexData = await _context.InstructorIndexData.FindAsync(id); if (InstructorIndexData != null) { _context.InstructorIndexData.Remove(InstructorIndexData); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } //prevent overposting var emptyCourse = new Course(); if (await TryUpdateModelAsync <Course>( emptyCourse, "course",//prefix in form fields) s => s.CourseID, s => s.DepartmentID, s => s.Title, s => s.Credits)) { _context.Course.Add(emptyCourse); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } PopulateDepartmentDropDownList(_context, emptyCourse.DepartmentID); return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (!ModelState.IsValid) { return(Page()); } var studentToUpdate = await _context.Student.FindAsync(id); if (await TryUpdateModelAsync <Student>( studentToUpdate, "student", // Prefix for form value. s => s.FirstMidName, s => s.LastName, s => s.EnrollmentDate)) { await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } return(RedirectToPage("./Index")); }