Beispiel #1
0
        /// <summary>
        /// Costruttore.
        /// </summary>
        /// <param name="db">IDataAccessDb</param>
        public AnteprimaSchedinaViewModel(IDataAccessDb db)
        {
            if (IsInDesignMode)
            {
                // design-mode
            }
            else
            {
                // INIT
                this.selectedSchedina  = new Schedina();
                this.selectedScommessa = new Scommessa();
                this.selectedIncontro  = new Incontro();
                this.listScommesse     = new ObservableCollection <Scommessa>();

                // DB
                this.dataAccessDb = db;

                // RELAY COMMAND
                NavToPageCommand              = new RelayCommand(InsertSchedinaCommandExecute);
                UpdateScommessaCommand        = new RelayCommand <string>(UpdateScommessaCommandExecute);
                DeleteScommessaCommand        = new RelayCommand <Scommessa>(DeleteScommessaCommandExecute);
                RemoveSelectedItemCommand     = new RelayCommand(RemoveSelectedItemCommandExecute);
                AlreadyUpdateScommessaCommand = new RelayCommand(AlreadyUpdateScommessaCommandExecute);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Costruttore.
        /// </summary>
        public HomeViewModel(IDataAccessDb db)
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
            }
            else
            {
                // Code runs "for real"

                // INIT
                this.nuovaSchedina = new Schedina()
                {
                    Title = Resources.AppResources.PanoramaPivot1ItemTitle
                };
                this.schedine = new ObservableCollection <Schedina>();

                // DB
                this.dataAccessDb = db;

                // RELAY COMMAND
                NavToPageCommand = new RelayCommand <Schedina>((s) =>
                {
                    if (s != null)
                    {
                        System.Diagnostics.Debug.WriteLine("[HOMEVIEWMODEL] " + "Tapped NavToPageCommand: " + s.Title.ToString());
                        string pageName      = "SchedinaView";
                        string pageParameter = s.Title.ToString();

                        Messenger.Default.Send <NavToPage>(new NavToPage {
                            PageName = pageName, PageParameter = pageParameter
                        });
                    }
                });

                DeleteSchedinaCommand = new RelayCommand <Schedina>(async(s) =>
                {
                    if (s != null && s.GetType() == typeof(Schedina))
                    {
                        System.Diagnostics.Debug.WriteLine("[HOMEVIEWMODEL] " + "Tapped DeleteCommand: " + s.Title.ToString());
                        bool isDeleted = await dataAccessDb.DeleteSchedina(s.Id);
                        if (isDeleted)
                        {
                            Schedine.Remove(s);
                        }
                        else
                        {
                            // TODO
                            // Notificare l'errore nella UI.
                        }
                    }
                });

                RefreshBindingData = new RelayCommand(PopolaPanoramaProperties);
            }
        }