Client wird gespeichert mittels interface
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using DaSaSo.Domain.Model;
|
||||
using DaSaSo.Domain.Services;
|
||||
using DaSaSo.ViewModel.Interface;
|
||||
using Microsoft.Toolkit.Mvvm.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -14,17 +15,19 @@ namespace DaSaSo.ViewModel
|
||||
{
|
||||
private Client _model;
|
||||
private IDataService<Client> _dataService;
|
||||
private readonly IActualProject _actualProject;
|
||||
|
||||
public Client Model { get => _model; set => _model = value; }
|
||||
|
||||
public IRelayCommand SaveClientCommand { get; set; }
|
||||
|
||||
|
||||
public ClientEditViewModel(IDataService<Client> dataService, Client model)
|
||||
public ClientEditViewModel(IDataService<Client> dataService, IActualProject actualProject)
|
||||
{
|
||||
this._model = model;
|
||||
this._dataService = dataService;
|
||||
SaveClientCommand = new RelayCommand(SaveClient);
|
||||
_actualProject = actualProject;
|
||||
this._model = _actualProject.AktuellClient;
|
||||
}
|
||||
|
||||
private void SaveClient()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using DaSaSo.Domain.Model;
|
||||
using DaSaSo.Domain.Services;
|
||||
using DaSaSo.ViewModel.Commands;
|
||||
using DaSaSo.ViewModel.Interface;
|
||||
using Microsoft.Toolkit.Mvvm.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,7 +22,7 @@ namespace DaSaSo.ViewModel
|
||||
IEnumerable<Client>? result;
|
||||
bool _isLoading = true;
|
||||
|
||||
public IRelayCommand SelectClientCommand { get; set; }
|
||||
public ICommand SelectCommand { get; set; }
|
||||
public IRelayCommand EditClientCommand { get; set; }
|
||||
public IRelayCommand AddNewClientCommand { get; set; }
|
||||
|
||||
@@ -32,8 +34,8 @@ namespace DaSaSo.ViewModel
|
||||
if(_selectedClient != value)
|
||||
{
|
||||
_selectedClient = value;
|
||||
SelectClientCommand.NotifyCanExecuteChanged();
|
||||
EditClientCommand.NotifyCanExecuteChanged();
|
||||
//SelectClientCommand.NotifyCanExecuteChanged();
|
||||
//EditClientCommand.NotifyCanExecuteChanged();
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
@@ -52,16 +54,16 @@ namespace DaSaSo.ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
public ClientListViewModel(IDataService<Client> dataService)
|
||||
public ClientListViewModel(IDataService<Client> dataService, IActualProject actualProject)
|
||||
{
|
||||
Clients = new ObservableCollection<Client>();
|
||||
_dataService = dataService;
|
||||
|
||||
|
||||
LoadClient();
|
||||
SelectClientCommand = new RelayCommand(SelectClient, () => SelectedClient != null);
|
||||
EditClientCommand = new RelayCommand(EditClient, () => SelectedClient != null);
|
||||
AddNewClientCommand = new RelayCommand(AddNewClient);
|
||||
SelectCommand = new SelectClientCommand(actualProject,this); //= new RelayCommand(SelectClient, () => SelectedClient != null);
|
||||
//EditClientCommand = new RelayCommand(EditClient, () => SelectedClient != null);
|
||||
//AddNewClientCommand = new RelayCommand(AddNewClient);
|
||||
|
||||
}
|
||||
|
||||
@@ -93,6 +95,7 @@ namespace DaSaSo.ViewModel
|
||||
|
||||
private void SelectClient()
|
||||
{
|
||||
|
||||
Mediator.Notify(Enums.EMediator.SELECTEDCLIENT, SelectedClient);
|
||||
}
|
||||
|
||||
|
||||
33
DaSaSo.ViewModel/Commands/SelectClientCommand.cs
Normal file
33
DaSaSo.ViewModel/Commands/SelectClientCommand.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using DaSaSo.ViewModel.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace DaSaSo.ViewModel.Commands
|
||||
{
|
||||
public class SelectClientCommand : ICommand
|
||||
{
|
||||
public event EventHandler? CanExecuteChanged;
|
||||
private readonly IActualProject _actualProject;
|
||||
private readonly ClientListViewModel _clientListViewModel;
|
||||
public SelectClientCommand(IActualProject actualProject, ClientListViewModel clientListViewModel)
|
||||
{
|
||||
_actualProject = actualProject;
|
||||
_clientListViewModel = clientListViewModel;
|
||||
}
|
||||
|
||||
public bool CanExecute(object? parameter)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Execute(object? parameter)
|
||||
{
|
||||
var s = _clientListViewModel.SelectedClient;
|
||||
_actualProject.SetClient(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ namespace DaSaSo.ViewModel.Enums
|
||||
{
|
||||
Home,
|
||||
Clients,
|
||||
ClientEdit,
|
||||
Projects,
|
||||
Buildingsites,
|
||||
SewerObjects
|
||||
|
||||
27
DaSaSo.ViewModel/Factories/ClientEditViewModelFactory.cs
Normal file
27
DaSaSo.ViewModel/Factories/ClientEditViewModelFactory.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using DaSaSo.Domain.Model;
|
||||
using DaSaSo.EntityFramework;
|
||||
using DaSaSo.EntityFramework.Services;
|
||||
using DaSaSo.ViewModel.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DaSaSo.ViewModel.Factories
|
||||
{
|
||||
public class ClientEditViewModelFactory : IViewModelFactory<ClientEditViewModel>
|
||||
{
|
||||
private readonly IActualProject _actualProject;
|
||||
|
||||
public ClientEditViewModelFactory(IActualProject actualProject)
|
||||
{
|
||||
_actualProject = actualProject;
|
||||
}
|
||||
|
||||
public ClientEditViewModel CreateViewModel()
|
||||
{
|
||||
return new ClientEditViewModel(new GenericDataService<Client>(new DaSaSoDbContextFactory()), _actualProject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,9 +12,16 @@ namespace DaSaSo.ViewModel.Factories
|
||||
{
|
||||
public class ClientListViewModelFactory : IViewModelFactory<ClientListViewModel>
|
||||
{
|
||||
private readonly IActualProject _actualProject;
|
||||
|
||||
public ClientListViewModelFactory(IActualProject actualProject)
|
||||
{
|
||||
_actualProject = actualProject;
|
||||
}
|
||||
|
||||
public ClientListViewModel CreateViewModel()
|
||||
{
|
||||
return new ClientListViewModel(new GenericDataService<Client>(new DaSaSoDbContextFactory()));
|
||||
return new ClientListViewModel(new GenericDataService<Client>(new DaSaSoDbContextFactory()),_actualProject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,12 +14,14 @@ namespace DaSaSo.ViewModel.Factories
|
||||
public class ViewModelAbstractFactory : IViewModelAbstractFactory
|
||||
{
|
||||
private IViewModelFactory<HomeViewModel> _homeViewModelFactory;
|
||||
private IViewModelFactory<ClientListViewModel> _clientListViewModel;
|
||||
private IViewModelFactory<ClientListViewModel> _clientListViewModelFactory;
|
||||
private IViewModelFactory<ClientEditViewModel> _clientEditViewModelFactory;
|
||||
|
||||
public ViewModelAbstractFactory(IViewModelFactory<HomeViewModel> homeViewModelFactory, IViewModelFactory<ClientListViewModel> clientListViewModel)
|
||||
public ViewModelAbstractFactory(IViewModelFactory<HomeViewModel> homeViewModelFactory, IViewModelFactory<ClientListViewModel> clientListViewModel, IViewModelFactory<ClientEditViewModel> clientEditViewModel)
|
||||
{
|
||||
_homeViewModelFactory = homeViewModelFactory;
|
||||
_clientListViewModel = clientListViewModel;
|
||||
_clientListViewModelFactory = clientListViewModel;
|
||||
_clientEditViewModelFactory = clientEditViewModel;
|
||||
}
|
||||
|
||||
public BaseViewModel CreateViewModel(EViewType viewType)
|
||||
@@ -30,7 +32,9 @@ namespace DaSaSo.ViewModel.Factories
|
||||
case EViewType.Home:
|
||||
return _homeViewModelFactory.CreateViewModel();
|
||||
case EViewType.Clients:
|
||||
return _clientListViewModel.CreateViewModel();
|
||||
return _clientListViewModelFactory.CreateViewModel();
|
||||
case EViewType.ClientEdit:
|
||||
return _clientEditViewModelFactory.CreateViewModel();
|
||||
/*case EViewType.Projects:
|
||||
break;
|
||||
case EViewType.Buildingsites:
|
||||
|
||||
18
DaSaSo.ViewModel/Interface/IActualProject.cs
Normal file
18
DaSaSo.ViewModel/Interface/IActualProject.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using DaSaSo.Domain.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DaSaSo.ViewModel.Interface
|
||||
{
|
||||
public interface IActualProject
|
||||
{
|
||||
Client AktuellClient { get; }
|
||||
Project AktuellProjekt { get; }
|
||||
Buildingsite AktuellBaustelle { get; }
|
||||
|
||||
void SetClient(Client client);
|
||||
}
|
||||
}
|
||||
24
DaSaSo.ViewModel/State/ActualState/ActualProject.cs
Normal file
24
DaSaSo.ViewModel/State/ActualState/ActualProject.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using DaSaSo.Domain.Model;
|
||||
using DaSaSo.ViewModel.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DaSaSo.ViewModel.State.ActualState
|
||||
{
|
||||
public class ActualProject : IActualProject
|
||||
{
|
||||
public Client AktuellClient { get; private set; }
|
||||
|
||||
public Buildingsite AktuellBaustelle { get; private set; }
|
||||
|
||||
public Project AktuellProjekt { get; private set; }
|
||||
|
||||
public void SetClient(Client client)
|
||||
{
|
||||
AktuellClient = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,44 +17,22 @@ 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)
|
||||
if(_selectedProject != value)
|
||||
{
|
||||
_selectedProject = value;
|
||||
OnPropertyChanged();
|
||||
ListBuildingsiteCommand.NotifyCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,15 +41,10 @@ namespace DaSaSo.ViewModel
|
||||
get => _selectedBuildingsite;
|
||||
set
|
||||
{
|
||||
if(value == null)
|
||||
{
|
||||
ListSewerObjectsCommand.NotifyCanExecuteChanged();
|
||||
}
|
||||
if(_selectedBuildingsite != value && value != null)
|
||||
if(_selectedBuildingsite != value)
|
||||
{
|
||||
_selectedBuildingsite = value;
|
||||
OnPropertyChanged();
|
||||
ListSewerObjectsCommand.NotifyCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,9 +57,8 @@ namespace DaSaSo.ViewModel
|
||||
if(_selectedClient != value)
|
||||
{
|
||||
_selectedClient = value;
|
||||
SelectedProject = null;
|
||||
//SelectedProject = null;
|
||||
OnPropertyChanged();
|
||||
ListProjectCommand.NotifyCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,10 +66,7 @@ namespace DaSaSo.ViewModel
|
||||
{
|
||||
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) =>
|
||||
{
|
||||
@@ -107,20 +76,14 @@ namespace DaSaSo.ViewModel
|
||||
|
||||
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()
|
||||
{
|
||||
@@ -134,8 +97,7 @@ namespace DaSaSo.ViewModel
|
||||
|
||||
private void listProjecte()
|
||||
{
|
||||
Debugger.Break();
|
||||
ActualViewModel = new ProjectListViewModel(new GenericDataService<Project>(new DaSaSoDbContextFactory()),SelectedClient);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
using DaSaSo.Domain.Model;
|
||||
using DaSaSo.Domain.Services;
|
||||
using DaSaSo.Domain.Services.ClientServices;
|
||||
using DaSaSo.EntityFramework;
|
||||
using DaSaSo.EntityFramework.Services;
|
||||
using DaSaSo.ViewModel;
|
||||
using DaSaSo.ViewModel.Factories;
|
||||
using DaSaSo.ViewModel.Interface;
|
||||
using DaSaSo.ViewModel.State.ActualState;
|
||||
using DaSaSo.ViewModel.State.Navigation;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace DaSaSo.Wpf
|
||||
@@ -23,7 +18,7 @@ namespace DaSaSo.Wpf
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
protected override async void OnStartup(StartupEventArgs e)
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
IServiceProvider serviceProvider = CreateServiceProvider();
|
||||
|
||||
@@ -43,6 +38,8 @@ namespace DaSaSo.Wpf
|
||||
services.AddSingleton<IViewModelAbstractFactory, ViewModelAbstractFactory>();
|
||||
services.AddSingleton<IViewModelFactory<HomeViewModel>, HomeViewModelFactory>();
|
||||
services.AddSingleton<IViewModelFactory<ClientListViewModel>, ClientListViewModelFactory>();
|
||||
services.AddSingleton<IViewModelFactory<ClientEditViewModel>, ClientEditViewModelFactory>();
|
||||
services.AddScoped<IActualProject, ActualProject>();
|
||||
services.AddScoped<INavigator, Navigator>();
|
||||
|
||||
services.AddScoped<MainWindowViewModel>();
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<RowDefinition Height="auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<RadioButton Grid.Row="0" Content="Kunden" Style="{StaticResource ToggleButtonList}" Command="{Binding UpdateViewModelCommand}" CommandParameter="{x:Static nav:EViewType.Clients}" />
|
||||
<RadioButton Grid.Row="1" Content="Projekte" Style="{StaticResource ToggleButtonList}" Command="{Binding UpdateViewModelCommand}" CommandParameter="{x:Static nav:EViewType.Projects}" />
|
||||
<RadioButton Grid.Row="1" Content="Projekte" Style="{StaticResource ToggleButtonList}" Command="{Binding UpdateViewModelCommand}" CommandParameter="{x:Static nav:EViewType.ClientEdit}" />
|
||||
<RadioButton Grid.Row="2" Content="Baustellen" Style="{StaticResource ToggleButtonList}" Command="{Binding UpdateViewModelCommand}" CommandParameter="{x:Static nav:EViewType.Buildingsites}" />
|
||||
<RadioButton Grid.Row="3" Content="Objekten" Style="{StaticResource ToggleButtonList}" Command="{Binding UpdateViewModelCommand}" CommandParameter="{x:Static nav:EViewType.SewerObjects}" />
|
||||
</Grid>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<StackPanel>
|
||||
<TextBlock Text="Kundenliste" />
|
||||
<ListView ItemsSource="{Binding Clients}" DisplayMemberPath="Firstname" SelectedItem="{Binding SelectedClient, Mode=TwoWay}"/>
|
||||
<Button Content="Kunde auswählen" Command="{Binding SelectClientCommand}" />
|
||||
<Button Content="Kunde auswählen" Command="{Binding SelectCommand}" />
|
||||
<Button Content="Kunde Editieren" Command="{Binding EditClientCommand}"/>
|
||||
<Button Content="Kunde Hinzufügen" Command="{Binding AddNewClientCommand}" />
|
||||
</StackPanel>
|
||||
|
||||
Reference in New Issue
Block a user