Exemple #1
0
        public async Task UpdateCommand()
        {
            switch (MainWindowViewModel.VM.CurrentPage)
            {
            case Navigator.Condiments:
            {
                // Finding that item in the database list
                var CondimentToUpdate = GetSelectedItemAsModelType <BackendHandler.Condiment, CondimentViewModel>(Condiment);

                // updates the type
                CondimentToUpdate.Type = CurrentType;

                // updates the price
                CondimentToUpdate.Price = float.Parse(CurrentPrice);

                // calling the database and updates the item
                await rep.UpdateCondiment(CondimentToUpdate);

                // refreshes the list in the UI
                await UpdateList();

                return;
            }

            case Navigator.Extras:
            {
                // Finding that item in the database list
                var ExtraToUpdate = GetSelectedItemAsModelType <BackendHandler.Extra, ExtraViewModel>(Extra);

                // updates the type
                ExtraToUpdate.Type = CurrentType;

                // updates the price
                ExtraToUpdate.Price = float.Parse(CurrentPrice);

                // calling the database and updates the item
                await rep.UpdateExtra(ExtraToUpdate);

                // refreshes the list in the UI
                await UpdateList();

                return;
            }

            case Navigator.Pizzas:
            {
                // Checks that nothing is null
                if (CurrentID == null || CurrentType == null || CurrentPrice == null)
                {
                    return;
                }

                // Creating a new instance of the item and fills up the properties
                var PizzaToUpdate = new PizzaViewModel()
                {
                    PizzaID = int.Parse(CurrentID), Type = CurrentType, Price = float.Parse(CurrentPrice), PizzabaseID = CurrentPizzaBaseID
                };

                // Creating a new instance of the window
                IngredientPopupWindow = new IngredientWindow(PizzaToUpdate);

                // And opens it up
                Nullable <bool> result = IngredientPopupWindow.ShowDialog();

                // If the suser closes the window without saving any changes, the return will be false
                if (result == false)
                {
                    return;
                }

                // If the user clicks the apply button, the return will be true
                else
                {
                    CurrentID    = null;
                    CurrentType  = null;
                    CurrentPrice = null;

                    await UpdateList();

                    return;
                }
            }
            }
        }
Exemple #2
0
        /// <summary>
        /// Command to add an item to the database
        /// </summary>
        /// <returns></returns>
        public async Task AddCommand()
        {
            CurrentID = "";

            switch (MainWindowViewModel.VM.CurrentPage)
            {
            case Navigator.Condiments:
            {
                // Creating a new instance of the item and fills up the properties
                var CondimentToAdd = new BackendHandler.Condiment()
                {
                    Type = CurrentType, Price = float.Parse(CurrentPrice)
                };

                // Calling the database and adds the item
                await rep.AddCondiment(CondimentToAdd);

                // Updates the list and the UI
                await UpdateList();

                return;
            }

            case Navigator.Extras:
            {
                // Creating a new instance of the item and fills up the properties
                var ExtraToAdd = new BackendHandler.Extra()
                {
                    Type = CurrentType, Price = float.Parse(CurrentPrice)
                };

                // Calling the database and adds the item
                await rep.AddExtra(ExtraToAdd);

                // Updates the list and the UI
                await UpdateList();

                return;
            }

            case Navigator.Pizzas:
            {
                // Checks that nothing is null
                if (CurrentType == null || CurrentPrice == null)
                {
                    return;
                }

                // Creating a new instance of the item and fills up the properties
                var PizzaToUpdate = new PizzaViewModel()
                {
                    Type = CurrentType, Price = float.Parse(CurrentPrice), PizzabaseID = CurrentPizzaBaseID
                };

                // Creating a new instance of the window
                IngredientPopupWindow = new IngredientWindow(PizzaToUpdate);

                // And opens it up
                Nullable <bool> result = IngredientPopupWindow.ShowDialog();

                // If the user closes the window without saving any changes, the return will be false
                if (result == false)
                {
                    return;
                }

                // If the user clicka tha apply button, the return will be true
                else
                {
                    await UpdateList();

                    return;
                }
            }
            }
        }