// POST api/MoneyRequisition public HttpResponseMessage PostMoneyRequisition(MoneyRequisition moneyrequisition) { if (ModelState.IsValid) { var xy = db.MoneyRequisitions.Where(x => x.MoneyRequisitionRequestID == moneyrequisition.MoneyRequisitionRequestID).Select(x => x.MoneyRequisitionRequestID).FirstOrDefault(); moneyrequisition.MoneyRequisitionID =Convert.ToInt64( xy); // db.MoneyRequisitions.Add(moneyrequisition); moneyrequisition.InsertBy = loginUser.UserID; db.Entry(moneyrequisition).State = moneyrequisition.MoneyRequisitionID == 0 ? EntityState.Added : EntityState.Modified; db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, moneyrequisition); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = moneyrequisition.MoneyRequisitionID })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// PUT api/MoneyRequisition/5 public HttpResponseMessage PutMoneyRequisition(long id, MoneyRequisition moneyrequisition) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != moneyrequisition.MoneyRequisitionID) { return Request.CreateResponse(HttpStatusCode.BadRequest); } moneyrequisition.UpdateBy = loginUser.UserID; db.Entry(moneyrequisition).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }