public void PutStudent(int id, Student stud) { stud.Id = id; dbCtxt.Students.Attach(stud); dbCtxt.Entry(stud).State = System.Data.EntityState.Modified; dbCtxt.SaveChanges(); }
public HttpResponseMessage PostStudent(Student stud) { if (!ModelState.IsValid) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState)); } dbCtxt.Students.Add(stud); int records = dbCtxt.SaveChanges(); var response = Request.CreateResponse(HttpStatusCode.Created, stud); response.Headers.Location = new Uri(Url.Link(ODataRouteNames.GetById, new { Controller = "Students", Id = stud.Id })); return response; }