Ejemplo n.º 1
0
        public MainPageViewModel()
        {
            // Save an instance of this ViewModel
            VM = this;

            // Creating the lists
            OrdersReadyToCook = new ThreadSafeObservableCollection <OrderViewModel>();
            PrioritizedOrders = new ThreadSafeObservableCollection <OrderViewModel>();
            OrdersWaiting     = new ThreadSafeObservableCollection <OrderViewModel>();

            LoadLists();

            // Creating the commands
            CookOrder = new RelayCommand((object order) =>
            {
                // Gets the selected order
                var ChosenOrderToCook = OrdersReadyToCook.Where(x => x.OrderID == (int)order).First();

                // Updates the static property of which ordet to cook
                OrderToCook = ChosenOrderToCook;

                // Changes page
                MainWindowViewModel.VM.CurrentPage = Navigator.Cooking;
            });
            Logout = new RelayCommand(RunLogout);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generic method that fills an Observable Collection from a IEnumerable from the database
        /// </summary>
        /// <typeparam name="ModelType">The model to take basic properties from</typeparam>
        /// <typeparam name="ModelViewModelType">The ViewModel of the model to create a Observable collection of</typeparam>
        /// <param name="dbList">The actual IEnumerable returned from the database</param>
        /// <returns></returns>
        public static async Task <ThreadSafeObservableCollection <ModelViewModelType> > FillListFromDatabase <ModelType, ModelViewModelType>(IEnumerable dbList)
            where ModelViewModelType : new()
        {
            IEnumerable <ModelType> databaseList = (dbList as IEnumerable <ModelType>);

            // the new list to return
            ThreadSafeObservableCollection <ModelViewModelType> result = new ThreadSafeObservableCollection <ModelViewModelType>();

            var properties = typeof(ModelType).GetProperties();

            // go through every item in the sent in database list
            databaseList.ToList().ForEach(item =>
            {
                // creates a new instance of the sent in ModelViewModel
                ModelViewModelType newItem = new ModelViewModelType();

                // goes trough every property in the database list and copies it to the new list
                Parallel.ForEach(databaseList, (currentProperty) =>
                {
                    for (int i = 0; i < properties.Length; i++)
                    {
                        newItem.GetType().GetProperty(properties[i].Name).SetValue(newItem,
                                                                                   item.GetType().GetProperty(properties[i].Name).GetValue(item));
                    }
                });

                // adds the new item to the list
                result.Add(newItem);
            });

            // returns the whole list as a Observable collection of the desired ModelViewModel type
            return(result);
        }
Ejemplo n.º 3
0
        public CookingPageViewModel()
        {
            // Setting singleton
            VM = this;

            // Getting the chosen order from the static reference
            _orderToCook = OrderToCook;

            // Creating new lists
            FoodsToCook = new ThreadSafeObservableCollection <PizzaViewModel>();
            CookedFoods = new ThreadSafeObservableCollection <PizzaViewModel>();

            // Gets all pizzas from the chosen order
            Task.Run(async() => await GetFoodsFromOrder()).Wait();

            // Creating new commands
            CookFood          = new RelayCommand(CookFoodCommand);
            Logout            = new RelayCommand(RunLogout);
            MarkOrderAsServed = new RelayCommand(MarkOrderAsServedCommand);
        }