public IHttpActionResult UpdateCourse(int id, Course course) { if (course == null) { return BadRequest(); } var toUpdate = _courses.SingleOrDefault(x => x.ID == id); if (toUpdate == null) { return NotFound(); } toUpdate.ID = course.ID; toUpdate.Name = course.Name; toUpdate.TemplateID = course.TemplateID; toUpdate.StartDate = course.StartDate; toUpdate.EndDate = course.EndDate; toUpdate.CourseStudents = course.CourseStudents; return Ok(toUpdate); }
public IHttpActionResult NewCourse([FromBody]Course course) { if(course == null) { return BadRequest(); } Random rnd = new Random(); Course newCourse = new Course { ID = rnd.Next(1, 100), Name = course.Name, TemplateID = course.TemplateID, StartDate = course.StartDate, EndDate = course.EndDate, CourseStudents = new List<Student>() }; var location = Request.RequestUri + "/" + newCourse.ID.ToString(); _courses.Add(newCourse); return Created(location, new { id = newCourse.ID }); }