// PUT api/Project/5 public HttpResponseMessage PutProject(int id, Project project) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != project.Id) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(project).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
// POST api/Project public HttpResponseMessage PostProject(Project project) { if (ModelState.IsValid) { db.Projects.Add(project); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, project); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = project.Id })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
public bool Insert(Project project) { try { _context.Projects.Add(project); return true; } catch { return false; } }
public bool Update(Project original, Project updated) { _context.Entry(original).CurrentValues.SetValues(updated); return true; }