public async Task<IHttpActionResult> PutPurchaseOrder(Guid id, PurchaseOrder purchaseOrder) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != purchaseOrder.ID) { return BadRequest(); } new PurchaseMgrAppService(db).UpdatePurchaseOrder(id, purchaseOrder); //db.Entry(purchaseOrder).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PurchaseOrderExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostPurchaseOrder(PurchaseOrder purchaseOrder) { if (!ModelState.IsValid) { return BadRequest(ModelState); } purchaseOrder.Creater = this.RequestContext.Principal.Identity.Name; new PurchaseMgrAppService(db).CreaterPurchaseOrder(purchaseOrder); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (PurchaseOrderExists(purchaseOrder.ID)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = purchaseOrder.ID }, purchaseOrder); }
public void UpdatePurchaseVoucher(PurchaseOrder order) { var existingOrder = db.PurchaseOrders.Find(order.ID); if (existingOrder != null) { db.Entry(existingOrder).CurrentValues.SetValues(order); } }