public async Task <IActionResult> Edit(int id, [Bind("StudentID,Name,Age,Active")] Student student) { if (id != student.StudentID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(student); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(student.StudentID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(student)); }
public async Task <IActionResult> Edit(int id, [Bind("CourseID,CourseName,Cost,Active")] Course course) { if (id != course.CourseID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(course); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CourseExists(course.CourseID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(course)); }
public async Task <IActionResult> Pay(int id, [Bind("ID,StudentID,CourseID,Paid,Active")] CourseSelection courseSelection) { if (id != courseSelection.ID) { return(NotFound()); } // Get the object of CourseSelection to be updated var courseSelectionToBeUpdated = await _context.CourseSelections.FindAsync(id); // Get the object of CourseSelectionOwing to be updated var courseSelectionOwingToBeUpdated = _context.CourseSelectionOwings.FirstOrDefault(m => m.CourseID == courseSelection.CourseID && m.StudentID == courseSelection.StudentID && m.Active == true); if (ModelState.IsValid) { courseSelectionToBeUpdated.Paid += courseSelection.Paid; courseSelectionOwingToBeUpdated.Owing -= courseSelection.Paid; try { // Update the entry of course selection _context.Update(courseSelectionToBeUpdated); // Update the entry of course selection owing _context.Update(courseSelectionOwingToBeUpdated); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CourseSelectionExists(courseSelection.ID)) { return(NotFound()); } else { throw; } } } var student = await GetStudentWithCourseSelections(courseSelectionToBeUpdated.StudentID); if (student == null) { return(NotFound()); } return(View(new CourseSelection { Student = student })); }