// POST api/PurchaseBillPayment public HttpResponseMessage PostPurchaseBillPayment(PurchaseBillPayment purchasebillpayment) { if (ModelState.IsValid) { ControlVoucher controlvoucher = new ControlVoucher(); long SupplierCOAID = (long)db.Collaborators.Where(c => c.CollaboratorID == purchasebillpayment.SupplierID).Select(c => c.SupplierCOAID).FirstOrDefault(); purchasebillpayment.VoucherNO = controlvoucher.CreateVoucher( SupplierCOAID,(long)purchasebillpayment.CreditTo, (decimal)purchasebillpayment.PaymentTotal, (long)1, (DateTime)purchasebillpayment.Date); purchasebillpayment.InsertBy = loginUser.UserID; db.PurchaseBillPayments.Add(purchasebillpayment); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, purchasebillpayment); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = purchasebillpayment.PurchaseBillPaymentID })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// PUT api/PurchaseBillPayment/5 public HttpResponseMessage PutPurchaseBillPayment(long id, PurchaseBillPayment purchasebillpayment) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != purchasebillpayment.PurchaseBillPaymentID) { return Request.CreateResponse(HttpStatusCode.BadRequest); } purchasebillpayment.UpdateBy = loginUser.UserID; db.Entry(purchasebillpayment).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }