public IHttpActionResult AddCourse(Course course) { if (course == null || string.IsNullOrWhiteSpace(course.Name) || course.StartDate > course.EndDate || string.IsNullOrWhiteSpace(course.TemplateID) || course.ID <= 0) { return StatusCode(HttpStatusCode.PreconditionFailed); } foreach (Course c in _courses) { if (c.ID == course.ID) { return Conflict(); } } _courses.Add(course); var location = Url.Link("GetCourse", new { id = course.ID }); return Created(location, course); }
public IHttpActionResult UpdateCourse(Course course) { if (course == null || string.IsNullOrWhiteSpace(course.Name) || course.StartDate > course.EndDate || string.IsNullOrWhiteSpace(course.TemplateID) || course.ID <= 0) { return StatusCode(HttpStatusCode.PreconditionFailed); } foreach (Course c in _courses) { if (c.ID == course.ID) { c.Name = course.Name; c.EndDate = course.EndDate; c.StartDate = course.StartDate; c.TemplateID = course.TemplateID; return StatusCode(HttpStatusCode.NoContent); } } return StatusCode(HttpStatusCode.NotFound); }