using DaSaSo.Domain.Model; using DaSaSo.EntityFramework; using DaSaSo.EntityFramework.Services; using Microsoft.Toolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace DaSaSo.ViewModel { public sealed class MainWindowViewModel : BaseViewModel { private BaseViewModel _actualViewModel; private Client _selectedClient; private Project _selectedProject; private Buildingsite _selectedBuildingsite; public IRelayCommand ListClientsCommand { get; set; } public IRelayCommand ListProjectCommand { get; set; } public IRelayCommand ListBuildingsiteCommand { get; set; } public IRelayCommand ListSewerObjectsCommand { get; set; } public BaseViewModel ActualViewModel { get => _actualViewModel; set { if(_actualViewModel != value) { _actualViewModel = value; OnPropertyChanged(); } } } public Project SelectedProject { get => _selectedProject; set { if(value == null) { ListBuildingsiteCommand.NotifyCanExecuteChanged(); } if(_selectedProject != value && value != null) { _selectedProject = value; OnPropertyChanged(); ListBuildingsiteCommand.NotifyCanExecuteChanged(); } } } public Buildingsite SelectedBuildingsite { get => _selectedBuildingsite; set { if(value == null) { ListSewerObjectsCommand.NotifyCanExecuteChanged(); } if(_selectedBuildingsite != value && value != null) { _selectedBuildingsite = value; OnPropertyChanged(); ListSewerObjectsCommand.NotifyCanExecuteChanged(); } } } public Client SelectedClient { get => _selectedClient; set { if(_selectedClient != value) { _selectedClient = value; SelectedProject = null; OnPropertyChanged(); ListProjectCommand.NotifyCanExecuteChanged(); } } } public MainWindowViewModel() { ListClientsCommand = new RelayCommand(showClients); ListProjectCommand = new RelayCommand(listProjecte, () => SelectedClient != null); ListBuildingsiteCommand = new RelayCommand(listBuildingsite, () => SelectedProject != null); ListSewerObjectsCommand = new RelayCommand(listSewerObjects, () => SelectedBuildingsite != null); Mediator.Subscribe(Enums.EMediator.SELECTEDCLIENT, (tt) => { SelectedClient = (Client)tt; listProjecte(); }); Mediator.Subscribe(Enums.EMediator.EDITCLIENT, (tt) => { ActualViewModel = new ClientEditViewModel(new GenericDataService(new DaSaSoDbContextFactory()), (Client)tt); }); Mediator.Subscribe(Enums.EMediator.SHOWCLIENT, (tt) => { ActualViewModel = null; }); } private void showClients() { ClientListViewModel clientListViewModel = new ClientListViewModel(new GenericDataService(new DaSaSoDbContextFactory())); ActualViewModel = clientListViewModel; clientListViewModel.LoadClient(); } private void listSewerObjects() { throw new NotImplementedException(); } private void listBuildingsite() { throw new NotImplementedException(); } private void listProjecte() { Debugger.Break(); ActualViewModel = new ProjectListViewModel(new GenericDataService(new DaSaSoDbContextFactory()),SelectedClient); } } }