Files
DaSaSo/DaSaSo.ViewModel/Window/MainWindowViewModel.cs
2021-09-14 17:08:06 +02:00

142 lines
4.7 KiB
C#

using DaSaSo.Domain.Model;
using DaSaSo.EntityFramework;
using DaSaSo.EntityFramework.Services;
using DaSaSo.ViewModel.Enums;
using DaSaSo.ViewModel.Interface;
using DaSaSo.ViewModel.State.Navigation;
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 INavigator Navigator { get; set; }
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(INavigator navigator)
{
this.Navigator = navigator;
Navigator.UpdateViewModelCommand.Execute(EViewType.Home);
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<Client>(new DaSaSoDbContextFactory()),
(Client)tt);
});
Mediator.Subscribe(Enums.EMediator.SHOWCLIENT, (tt) => {
ActualViewModel = null;
});
}
private void showClients()
{
ClientListViewModel clientListViewModel = new ClientListViewModel(new GenericDataService<Client>(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<Project>(new DaSaSoDbContextFactory()),SelectedClient);
}
}
}