public IActionResult GetStudentSubject([FromQuery] int Id, int Subj_Id, int Grade) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var studentSubject = _context.StudentsSubjects.Include(s => s.Subject.Instructor.User).Include(s => s.Student.User).SingleOrDefault(s => s.Subj_Id == Subj_Id && s.Id == Id); if (studentSubject == null) { return(NotFound()); } studentSubject.Grade = Grade; _context.SaveChanges(); return(Ok(studentSubject)); }
public IActionResult PostSubject([FromBody] Subject subject) { //if (!ModelState.IsValid) //{ // return BadRequest(ModelState); //} if (subject.Subj_Id != 0) { subject.Subj_Id = 0; } subject.Instructor.User = null; subject.Instructor = null; _context.Subjects.Add(subject); _context.SaveChanges(); return(CreatedAtAction("GetSubject", new { id = subject.Subj_Id }, subject)); }
public IActionResult DeleteInstructor([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var instructor = _context.Instructors.Include(i => i.User).SingleOrDefault(i => i.Id == id); User user = instructor.User; if (instructor == null) { return(NotFound()); } _context.Instructors.Remove(instructor); _context.Users.Remove(user); _context.SaveChanges(); return(Ok(instructor)); }
public IActionResult DeleteStudent([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var student = _context.Students.Include(s => s.User).SingleOrDefault(s => s.Id == id); if (student == null) { return(NotFound()); } var studentsSubjects = _context.StudentsSubjects.Where(s => s.Id == id).ToList(); User user = student.User; _context.StudentsSubjects.RemoveRange(studentsSubjects); _context.Students.Remove(student); _context.Users.Remove(user); _context.SaveChanges(); return(Ok(student)); }