コード例 #1
0
        public object PutStudent(int id, Student student)
        {
            student.id = id;

            if (!ModelState.IsValid)
            {
                return(Content(HttpStatusCode.BadRequest, new { ModelState, hateoas = new HateOAS("http://localhost:65191/api/Errors/400", "error.400") }));
            }

            try {
                db.Entry(student).State = EntityState.Modified;
                db.SaveChanges();
                return(Content(HttpStatusCode.OK, new StudentApi(student, new HateOAS("http://localhost:65191/api/Students/" + student.id, "self"))));
            } catch (DbUpdateConcurrencyException) {
                if (!StudentExists(id))
                {
                    return(Content(HttpStatusCode.NotFound, new HateOAS("http://localhost:65191/api/Errors/404", "error.404")));
                }
                else
                {
                    throw;
                }
            }
        }