示例#1
0
        private void SimulateUpdateOrder(OrdersViewModel ordersViewModel)
        {
            if (currentOrderId <= 0)
            {
                // at least one order must be created for the update
                return;
            }

            // ---------------------------------------------------
            // In a non test mode we would receive the data of the
            // updated order from the logic/model layer with the
            // values updated with the correct business logic.
            // For testing purposes get the order state directly
            // from the view model list and update the values with
            // a dummy logic.
            // ---------------------------------------------------

            // Choose a random order to update...
            var randIndexToUpdate = random.Next(0, currentOrderId - 1);
            var orderVM           = ordersViewModel.GetOrderVMByIndex(randIndexToUpdate); // O(1)

            // but simulate as if we had to find the order using the ID
            orderVM = ordersViewModel.GetOrderVMByID(orderVM.Id);

            var cumQtyToUpdate = int.Parse(orderVM.CumQty);

            cumQtyToUpdate    = int.Parse(orderVM.LeavesQty) > 0 ? cumQtyToUpdate + 1 : cumQtyToUpdate;
            orderVM.CumQty    = cumQtyToUpdate.ToString();
            orderVM.LeavesQty = (int.Parse(orderVM.OrdQty) - cumQtyToUpdate).ToString();

            // do some random chance to update the following fields
            var chanceToUpdateValues = random.Next(1, 10);

            if (chanceToUpdateValues % 2 == 0)
            {
                orderVM.TotalValue = random.Next(0, 1000).ToString();
            }
            if (chanceToUpdateValues % 3 == 0)
            {
                orderVM.AvailableValue = random.Next(0, 1000).ToString();
            }
            orderVM.GoalValue = random.Next(0, 1000).ToString();
            Application.Current.Dispatcher.BeginInvokeOnMainThread(() => orderVM.Update());
        }