// POST api/WorkFlow public HttpResponseMessage PostWorkFlow(WorkFlow workflow) { if (ModelState.IsValid) { workflow.InsertBy = loginUser.UserID; db.WorkFlows.Add(workflow); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, workflow); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = workflow.WorkFlowID })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// PUT api/WorkFlow/5 public HttpResponseMessage PutWorkFlow(long id, WorkFlow workflow) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != workflow.WorkFlowID) { return Request.CreateResponse(HttpStatusCode.BadRequest); } workflow.UpdateBy = loginUser.UserID; db.Entry(workflow).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }