public async Task <IActionResult> CreateCourse([FromBody] Course course) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Courses.Add(course); await db.SaveChangesAsync(); return(CreatedAtRoute("GetCourse", new { id = course.CourseId }, course)); }
public async Task <IActionResult> CreateInstructor([FromBody] Instructor instructor) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Instructors.Add(instructor); await db.SaveChangesAsync(); return(CreatedAtRoute("GetInstructor", new { id = instructor.Id }, instructor)); }
public async Task <IActionResult> CreateDepartment([FromBody] Department department) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Departments.Add(department); await db.SaveChangesAsync(); return(CreatedAtRoute("GetDepartment", new { id = department.DepartmentId }, department)); }
public async Task <IActionResult> CreateStudent([FromBody] Student student) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Students.Add(student); await db.SaveChangesAsync(); return(new OkObjectResult(student)); }