public IHttpActionResult PostSaleOrder(SaleOrder saleOrder) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if(saleOrder.CustomerID==Guid.Empty) { return BadRequest(); } SaleOrder newSaleOrder = SaleOrder.Create(saleOrder.CustomerID); db.SaleOrders.Add(newSaleOrder); try { db.SaveChanges(); } catch (DbUpdateException) { if (SaleOrderExists(saleOrder.ID)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = saleOrder.ID }, saleOrder); }
public static SaleOrder Create(Guid customerID,SaleOrder parentSaleOrder = null) { SaleOrder saleOrder = new SaleOrder(); saleOrder.CustomerID = customerID; saleOrder.Items = new HashSet<SaleOrderItem>(); saleOrder.OrderTime = DateTime.Now; saleOrder.ParentSaleOrder = parentSaleOrder; return saleOrder; }
public static SaleOrder Create(Guid customerID, SaleOrder parentSaleOrder = null) { SaleOrder saleOrder = new SaleOrder(); saleOrder.CustomerID = customerID; saleOrder.Items = new HashSet <SaleOrderItem>(); saleOrder.OrderTime = DateTime.Now; saleOrder.ParentSaleOrder = parentSaleOrder; return(saleOrder); }
public SaleOrder UpdateSaleOrder(SaleOrder saleOrder) { if (saleOrder.ID==Guid.Empty) { saleOrder.OrderTime = DateTime.Now; db.SaleOrders.Add(saleOrder); } else { var existingSaleOrder = db.SaleOrders.Find(saleOrder.ID); } return saleOrder; }
public IHttpActionResult PutSaleOrder(Guid id, SaleOrder saleOrder) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != saleOrder.ID) { return BadRequest(); } db.Entry(saleOrder).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!SaleOrderExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public void UpdateBy(SaleOrder saleOrder) { this.CustomerID = saleOrder.CustomerID; this.DeliveryAddress = saleOrder.DeliveryAddress; this.UpdateItems(saleOrder.Items); }