示例#1
0
        public AddNewSectionPageViewModel(ISectionsStorage sectionsStorage, Section parent)
        {
            this.sectionsStorage = sectionsStorage;
            this.parent          = parent;

            AddNewSectionCommand = new RelayCommand(OnAddNewSectionCommandExecute);
        }
示例#2
0
        public MainPage(ISectionsStorage sectionsStorage)
        {
            this.sectionsStorage = sectionsStorage;

            InitializeComponent();

            DataContext = new MainPageViewModel(sectionsStorage, AutofacContainer.Resolve <IEventAggregator>());
        }
示例#3
0
        public EditSectionPageViewModel(ISectionsStorage sectionsStorage, Section section)
        {
            this.sectionsStorage = sectionsStorage;
            this.section         = section;
            Name = section.Name;

            AddNewSectionCommand = new RelayCommand(() => {
                section.Name = Name;
                sectionsStorage.Save();
                Complete?.Invoke(this, EventArgs.Empty);
            });
        }
示例#4
0
        public MainPageViewModel(ISectionsStorage sectionsStorage, IEventAggregator eventAggregator)
        {
            this.sectionsStorage = sectionsStorage;
            this.eventAggregator = eventAggregator;
            root = null;

            ShowAddSectionDialogCommand = new RelayCommand(() => {
                var result = AutofacContainer.Resolve <IDialogService>().Show <AddNewSectionPage>(new AddNewSectionPageViewModel(sectionsStorage, root));

                if (result == true)
                {
                    Sections = new ObservableCollection <Section>(root?.Children ?? sectionsStorage.Sections);
                    OnPropertyChanged(nameof(Sections));
                }
            });

            EditSectionCommand = new RelayCommand <Section>(s => {
                var result = AutofacContainer.Resolve <IDialogService>().Show <AddNewSectionPage>(new EditSectionPageViewModel(sectionsStorage, s));

                if (result == true)
                {
                    Sections = new ObservableCollection <Section>(sectionsStorage.Sections);
                    OnPropertyChanged(nameof(Sections));
                }
            });

            DeleteSectionCommand = new RelayCommand <Guid>(guid => {
                if (MessageBox.Show("Удалить раздел, включая все подразделы?", "Удаление раздела", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    sectionsStorage.RemoveSection(guid);
                    Sections = new ObservableCollection <Section>(sectionsStorage.Sections);
                    OnPropertyChanged(nameof(Sections));
                }
            });

            OpenSectionCommand = new RelayCommand <Section>(section => {
                Sections = new ObservableCollection <Section>(section.Children);
                root     = section;
                eventAggregator.GetEvent <SectionChangedEvent>().Publish(section);
                OnPropertyChanged(nameof(Sections));
            });

            CloseSectionCommand = new RelayCommand(() => {
                if (root == null)
                {
                    return;
                }

                if (root.Parent == null)
                {
                    Sections = new ObservableCollection <Section>(sectionsStorage.Sections);
                }
                else
                {
                    Sections = new ObservableCollection <Section>(root.Parent.Children ?? sectionsStorage.Sections);
                }

                OnPropertyChanged(nameof(Sections));
                root = root.Parent;

                eventAggregator.GetEvent <SectionChangedEvent>().Publish(root);
            });

            sectionsStorage.Load();
            Sections = new ObservableCollection <Section>(sectionsStorage.Sections);
        }