// POST api/Tasks public HttpResponseMessage PostProjectTask(ProjectTask projecttask) { if (ModelState.IsValid) { db.ProjectTasks.Add(projecttask); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, projecttask); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = projecttask.Id })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
// PUT api/Tasks/5 public HttpResponseMessage PutProjectTask(int id, ProjectTask projecttask) { if (ModelState.IsValid && id == projecttask.Id) { db.Entry(projecttask).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }