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