// POST api/ProjectSetup public HttpResponseMessage PostProjectSetup(ProjectSetup projectsetup) { if (ModelState.IsValid) { //db.ProjectSetups.Add(projectsetup); projectsetup.InsertBy = loginUser.UserID; db.Entry(projectsetup).State = projectsetup.ProjectID == 0 ? EntityState.Added : EntityState.Modified; db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, projectsetup); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = projectsetup.ProjectID })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// PUT api/ProjectSetup/5 public HttpResponseMessage PutProjectSetup(long id, ProjectSetup projectsetup) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != projectsetup.ProjectID) { return Request.CreateResponse(HttpStatusCode.BadRequest); } projectsetup.UpdateBy = loginUser.UserID; db.Entry(projectsetup).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }