Example #1
0
        public void EditWidget(object parameter)
        {
            //
            // TODO - add code to validate user input
            //

            string commandParameter = parameter.ToString();

            if (commandParameter == "SAVE")
            {
                if (WidgetToEdit != null)
                {
                    Widget widgetToDelete = SelectedWidget;
                    Widgets.Add(WidgetToEdit);
                    SelectedWidget = WidgetToEdit;
                    Widgets.Remove(widgetToDelete);

                    WidgetOperationFeedback = "Widget Updated";
                }
            }
            else if (commandParameter == "CANCEL")
            {
                WidgetToEdit            = SelectedWidget.Copy();
                WidgetOperationFeedback = "Widget Update Canceled";
            }
            else
            {
                throw new ArgumentException($"{commandParameter} is not a valid command parameter for the adding widgets.");
            }
        }
Example #2
0
        public void EditWidget(object parameter)
        {
            //
            // TODO - add code to validate user input
            //

            string commandParameter = parameter.ToString();

            if (commandParameter == "LOADWIDGET")
            {
                //
                // Copy method uses makes a Shallow Copy
                //
                WidgetToEdit = SelectedWidget.Copy();
            }
            else if (commandParameter == "SAVE")
            {
                if (WidgetToAdd != null)
                {
                    Widgets.Remove(SelectedWidget);
                    Widgets.Add(WidgetToEdit);
                    AddWidgetFeedback = "Widget Updated";
                }
            }
            else if (commandParameter == "CANCEL")
            {
                AddWidgetFeedback = "Widget Update Canceled";
            }
            else
            {
                throw new ArgumentException($"{commandParameter} is not a valid command parameter for the adding widgets.");
            }
            WidgetToEdit = new Widget();
        }
Example #3
0
        public MainWindowViewModel()
        {
            Widgets = new ObservableCollection <Widget>(WidgetData.GetAllWidgets());

            if (Widgets.Any())
            {
                SelectedWidget = Widgets[0];
            }

            ButtonSellCommand   = new RelayCommand(new Action <object>(SellWidgets));
            ButtonBuyCommand    = new RelayCommand(new Action <object>(BuyWidgets));
            ButtonAddCommand    = new RelayCommand(new Action <object>(AddWidget));
            ButtonEditCommand   = new RelayCommand(new Action <object>(EditWidget));
            ButtonDeleteCommand = new RelayCommand(new Action <object>(DeleteWidget));
            ButtonQuitCommand   = new RelayCommand(new Action <object>(QuitWidget));

            WidgetToAdd  = new Widget();
            WidgetToEdit = SelectedWidget.Copy();
        }