예제 #1
0
        // Update specific student
        public StudentUpdate UpdateStudent(StudentUpdate updatedstudent)
        {
            var e = ds.Students.Find(updatedstudent.StudentId);

                if (e == 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(e).CurrentValues.SetValues(updatedstudent);
                    ds.SaveChanges();
                    return updatedstudent;
                }
        }
예제 #2
0
 public HttpResponseMessage PutStudent(int id, StudentUpdate student)
 {
     if (ModelState.IsValid && id == student.StId)
     {
         // Attempt to update the item
         var updatedstudent = r.UpdateStudent(student);
         return (updatedstudent == null) ?
             Request.CreateResponse(HttpStatusCode.BadRequest) :
             Request.CreateResponse(HttpStatusCode.OK, updatedstudent);
     }
     else
     {
         return Request.CreateResponse(HttpStatusCode.BadRequest);
     }
 }