public IHttpActionResult CreateOrder(Order order) { if (!this.ModelState.IsValid) { return BadRequest(ModelState); } if (order == null) { return BadRequest("You must provide an entry of type 'Order', 'NULL' provided."); } // TODO: Fix it! this.data.Orders.Add(order); // throwing an exception {"The property 'StockId' cannot be configured as a navigation property. The property must be a valid entity type and the property should have a non-abstract getter and setter. For collection properties the type must implement ICollection<T> where T is a valid entity type."} this.data.SaveChanges(); return Ok(order); }
public IHttpActionResult UpdateOrder(int id, Order order) { if (!this.ModelState.IsValid) { return BadRequest(ModelState); } Order orderToUpdate = this.data.Orders.FirstOrDefault(o => o.Id == id); if (orderToUpdate == null) { return BadRequest(string.Format("Failed to update order. No order with id {0} found.", id)); } orderToUpdate.AccountId = order.AccountId; orderToUpdate.CreatedOn = order.CreatedOn; orderToUpdate.IsExecuted = order.IsExecuted; orderToUpdate.Price = order.Price; orderToUpdate.Shares = order.Shares; orderToUpdate.StockId = order.StockId; this.data.SaveChanges(); return Ok(order); }