public HttpResponseMessage PutCourse(int id, CourseUpdate course)
 {
     if (ModelState.IsValid && id == course.CourseId)
     {
         // Attempt to update the item
         var updatedcourse = r.UpdateCourse(course);
         return (updatedcourse == null) ?
             Request.CreateResponse(HttpStatusCode.BadRequest) :
             Request.CreateResponse(HttpStatusCode.OK, updatedcourse);
     }
     else
     {
         return Request.CreateResponse(HttpStatusCode.BadRequest);
     }
 }
Example #2
0
        // Update specific item
        public CourseUpdate UpdateCourse(CourseUpdate updatedCourse)
        {
            var p = ds.Courses.Find(updatedCourse.Id);

            if (p == null)
            {
                return null;
            }
            else
            {
                // For the object fetched from the data store,
                // set its values to those provided
                // (the method ignores missing properties, and navigation properties)
                ds.Entry(p).CurrentValues.SetValues(updatedCourse);
                ds.SaveChanges();
                return updatedCourse;
            }
        }