コード例 #1
0
        /// <summary>
        /// Initial Load Orders from SQL
        /// </summary>
        async void LoadOrders()
        {
            // Boot up sql
            var repo = new Library.Repository.OrdersRepository("orders");
            var res  = await repo.GetAllAsync();

            // using the Enum.Foreach extension
            res.ForEach(item => { if (item.Orderstatus == 1)
                                  {
                                      Orders.Add(item);
                                  }
                                  if (item.Orderstatus == 2)
                                  {
                                      OrdersDone.Add(item);
                                  }
                        });
        }
コード例 #2
0
        /// <summary>
        /// Method for managing orders coming in from the other terminals
        /// over web API throws an exception if the ordernumber is incorrect for the call
        /// that the client can use to know that it was an incorrect call
        /// </summary>
        /// <param name="orderNo">The order's Number</param>
        /// <param name="typeOrder">Type of order command: PlaceOrder, DoneOrder, RemoveOrder</param>
        private void ManageOrders(int orderNo, TypeOrder typeOrder)
        {
            Trace.WriteLine(typeOrder.ToString() + " ");
            switch (typeOrder)
            {
            // handle a new order. throws an exception if there is already an order with same number
            case TypeOrder.placeorder:
                if (Orders.Any(x => x.ID == orderNo) != true)
                {
                    Orders.Add(new Order {
                        ID = orderNo, CustomerID = 99, Orderstatus = 0, Price = 99, TimeCreated = GetRandomTime()
                    });
                }
                else
                {
                    throw new Exception();
                }
                break;

            // handle an order that is ready to get picked up. throws an exception if there isnt any order with that ordernumber
            case TypeOrder.doneorder:
                var tempOrder = Orders.Single(x => x.ID == orderNo);
                if (Orders.Contains(tempOrder) == true)
                {
                    Orders.Remove(tempOrder);
                    tempOrder.Orderstatus = 1;
                    OrdersDone.Add(tempOrder);
                }
                break;

            // handle removing an order. throws an exception if there isnt any order with that ordernumber
            case TypeOrder.removeorder:
                tempOrder = OrdersDone.Single(x => x.ID == orderNo);
                if (OrdersDone.Contains(tempOrder) == true)
                {
                    OrdersDone.Remove(tempOrder);
                }
                break;

            default:
                throw new Exception();
                break;
            }
        }