Пример #1
0
        // Update specific subject
        public SubjectUpdate UpdateSubject(SubjectUpdate updatedSubject)
        {
            var s = ds.Subjects.Find(updatedSubject.SubjectId);

            if (s == 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(s).CurrentValues.SetValues(updatedSubject);
                ds.SaveChanges();
                return updatedSubject;
            }
        }
Пример #2
0
 public HttpResponseMessage PutSub(int id, SubjectUpdate subject)
 {
     if (ModelState.IsValid && id == subject.SubjectId)
     {
         // Attempt to update the item
         var updatedSubject = r.UpdateSubject(subject);
         return (updatedSubject == null) ?
             Request.CreateResponse(HttpStatusCode.BadRequest) :
             Request.CreateResponse(HttpStatusCode.OK, updatedSubject);
     }
     else
     {
         return Request.CreateResponse(HttpStatusCode.BadRequest);
     }
 }