65 lines
1.9 KiB
C#
65 lines
1.9 KiB
C#
using Aufgabe17.Framework;
|
|
using Aufgabe17.ViewModels;
|
|
using Aufgabe17.Views;
|
|
using Autofac;
|
|
|
|
namespace Aufgabe17.Controllers
|
|
{
|
|
public class MainWindowController
|
|
{
|
|
// Standard Sichtbarkeit für Member: private
|
|
// Könnte man deswegen auch weglassen
|
|
private MainWindow mView;
|
|
private MainWindowViewModel mViewModel;
|
|
private App mApplication;
|
|
|
|
// Hier "dependency injection"
|
|
// Der holt das mainWindow aus dem Container
|
|
public MainWindowController(MainWindow mainWindow, MainWindowViewModel mainWindowViewModel, App application)
|
|
{
|
|
mView = mainWindow;
|
|
mViewModel = mainWindowViewModel;
|
|
mApplication = application;
|
|
|
|
// Hier ist die Verbindung zwischen View und ViewModel
|
|
mView.DataContext = mViewModel;
|
|
mApplication.MainWindow = mView;
|
|
|
|
mViewModel.AddCommand = new RelayCommand(ExecuteAddCommand);
|
|
mViewModel.DeleteCommand = new RelayCommand(ExecuteDeleteCommand, CanExecuteDeleteCommand);
|
|
}
|
|
|
|
|
|
public void ExecuteAddCommand(object command)
|
|
{
|
|
WindowAddController windowAddController = this.mApplication.Container.Resolve<WindowAddController>();
|
|
|
|
var zurueck = windowAddController.AddEmployee();
|
|
if (zurueck != null)
|
|
{
|
|
this.mViewModel.Models.Add(zurueck);
|
|
}
|
|
}
|
|
|
|
|
|
public void ExecuteDeleteCommand(object command)
|
|
{
|
|
if (this.mViewModel.SelectedModel != null)
|
|
{
|
|
this.mViewModel.Models.Remove(this.mViewModel.SelectedModel);
|
|
}
|
|
}
|
|
|
|
|
|
public bool CanExecuteDeleteCommand(object parameter)
|
|
{
|
|
return this.mViewModel.SelectedModel != null;
|
|
}
|
|
|
|
|
|
public void Initialize()
|
|
{
|
|
this.mView.ShowDialog();
|
|
}
|
|
}
|
|
} |