Esempio n. 1
0
        public SettingsViewModel(IDialogCoordinator coordinator)
        {
            _dialogCoordinator = coordinator;

            DatabaseImport = new RelayCommand(x =>
            {
                var dlg = new OpenFileDialog {
                    Filter = "Zip filer (.zip)|*.zip"
                };
                dlg.FileOk += ValidateDatabaseFile;
                var result  = dlg.ShowDialog();
                if (result == true)
                {
                    ApplicationDatabase.Import(dlg.FileName);
                    DisplayTimedMessage("Succes", "Databasen er importeret succesfuldt. ", 2);
                }
                DatabaseExport.NotifyCanExecuteChanged();
            });

            DatabaseExport = new RelayCommand(x =>
            {
                var dlg = new SaveFileDialog {
                    Filter = "Zip filer (.zip)|*.zip", FileName = "database", DefaultExt = ".zip"
                };
                var result = dlg.ShowDialog();
                if (result != true)
                {
                    return;
                }
                ApplicationDatabase.Export(dlg.FileName);
                DisplayTimedMessage("Succes", "Databasen er eksporteret succesfuldt. ", 2);
            }, x => ApplicationDatabase.Exists);

            RunOfferSettingsDialogCmd = new RelayCommand(x =>
            {
                OpenOfferSettingsDialog(instanceCanceled =>
                {
                    _dialogCoordinator.HideMetroDialogAsync(this, _customDialog);
                }, async instanceCompleted =>
                {
                    await _dialogCoordinator.HideMetroDialogAsync(this, _customDialog);
                    DisplayTimedMessage("Information gemt!", "", 2);
                });
            });

            NavigateBackCmd = new RelayCommand(async x =>
            {
                if (!IsDataSaved)
                {
                    var result = await NavigationService.ConfirmDiscardChanges(_dialogCoordinator);
                    if (result == false)
                    {
                        return;
                    }
                }
                NavigationService.GoBack();
            });
        }