/// <summary> /// Creates a new Order with default values /// </summary> /// <returns></returns> public Order Create() { Order Order = new Order { orderDate = DateTime.Now }; return Order; }
/// <summary> /// Saves a new Order. /// </summary> /// <param name="Order"></param> /// <returns></returns> public Order Save(Order Order) { // Read in the existing Orders var Orders = this.Retrieve(); // Assign a new Id var maxId = Orders.Max(p => p.id); Order.id = maxId + 1; Orders.Add(Order); WriteData(Orders); return Order; }
/// <summary> /// Updates an existing Order /// </summary> /// <param name="id"></param> /// <param name="Order"></param> /// <returns></returns> public Order Save(int id, Order Order) { // Read in the existing Orders var Orders = this.Retrieve(); // Locate and replace the item var itemIndex = Orders.FindIndex(p => p.id == Order.id); if (itemIndex > 0) { Orders[itemIndex] = Order; } else { return null; } WriteData(Orders); return Order; }