Projekt kann nun Selectiert werden

This commit is contained in:
HuskyTeufel
2021-08-31 13:56:13 +02:00
parent ade84e30e3
commit 97fdc31e21
4 changed files with 28 additions and 1 deletions

View File

@@ -245,10 +245,24 @@ namespace KanSan.ViewModel
Mediator.Subscribe("GoToEditClientScreen", OnGoToEditClientScreen); Mediator.Subscribe("GoToEditClientScreen", OnGoToEditClientScreen);
Mediator.Subscribe("ClientSelected", OnSelectedClient); Mediator.Subscribe("ClientSelected", OnSelectedClient);
Mediator.Subscribe("GoToListProjektScreen", OnGoToListProjektScreen);
Mediator.Subscribe("GoToEditProjektScreen", OnGoToEditProjektScreen); Mediator.Subscribe("GoToEditProjektScreen", OnGoToEditProjektScreen);
Mediator.Subscribe("ProjektSelected", OnSelectedProjekt);
} }
private void OnSelectedProjekt(object obj)
{
if (!(obj is Projekt)) return;
SelectedProjekt = (obj as Projekt);
ListBaustellen();
}
private void OnGoToListProjektScreen(object obj)
{
ListProjekte();
}
private void OnGoToEditProjektScreen(object obj) private void OnGoToEditProjektScreen(object obj)
{ {
if (!(obj is Projekt)) return; if (!(obj is Projekt)) return;

View File

@@ -2,16 +2,20 @@
using KanSan.Base.Interfaces; using KanSan.Base.Interfaces;
using KanSan.Base.Interfaces.UI; using KanSan.Base.Interfaces.UI;
using KanSan.Base.Models; using KanSan.Base.Models;
using KanSan.ViewModel.Commands;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Text; using System.Text;
using System.Windows.Input;
namespace KanSan.ViewModel namespace KanSan.ViewModel
{ {
public class ProjektEditViewModel : BaseViewModel,INotifyPropertyChanged, IProjektEditViewModel public class ProjektEditViewModel : BaseViewModel,INotifyPropertyChanged, IProjektEditViewModel
{ {
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext()); IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
public ICommand SaveProjekt { get; set; }
public ICommand RemoveProjekt { get; set; }
private Projekt projekt; private Projekt projekt;
string projektnummer; string projektnummer;
string ort; string ort;
@@ -41,6 +45,7 @@ namespace KanSan.ViewModel
this.projekt = projekt; this.projekt = projekt;
projektnummer = projekt.Projektnummer; projektnummer = projekt.Projektnummer;
ort = projekt.Ort; ort = projekt.Ort;
SaveProjekt = new RelayCommand(parameter => Speichern());
} }
public void Speichern() public void Speichern()
@@ -49,6 +54,7 @@ namespace KanSan.ViewModel
projekt.Projektnummer = Projektnummer; projekt.Projektnummer = Projektnummer;
unitOfWork.ProjekteRepository.Update(projekt); unitOfWork.ProjekteRepository.Update(projekt);
unitOfWork.Commit(); unitOfWork.Commit();
Mediator.Notify("GoToListProjektScreen");
} }
} }
} }

View File

@@ -37,10 +37,17 @@ namespace KanSan.ViewModel
projektevonKunde = unitOfWork.ProjekteRepository.Get(x => x.Kunde.Equals(client)).ToList(); projektevonKunde = unitOfWork.ProjekteRepository.Get(x => x.Kunde.Equals(client)).ToList();
SelectProjekt = new RelayCommand(parameter => SelectActualProjekt());
EditProjekt = new RelayCommand(parameter => EditSelectedProjekt()); EditProjekt = new RelayCommand(parameter => EditSelectedProjekt());
NewProjekt = new RelayCommand(parameter => AddNewProjekt()); NewProjekt = new RelayCommand(parameter => AddNewProjekt());
} }
private void SelectActualProjekt()
{
if (SelectedProjekt == null) return;
Mediator.Notify("ProjektSelected", SelectedProjekt);
}
private void AddNewProjekt() private void AddNewProjekt()
{ {
Projekt newProj = NeueProjekt(); Projekt newProj = NeueProjekt();

View File

@@ -23,7 +23,7 @@
<Label Background="Beige" Grid.Column="0" Grid.Row="0" Content="Projektnummer" /> <Label Background="Beige" Grid.Column="0" Grid.Row="0" Content="Projektnummer" />
<Label Background="Beige" Grid.Column="0" Grid.Row="1" Content="Ort" /> <Label Background="Beige" Grid.Column="0" Grid.Row="1" Content="Ort" />
<Button Grid.Row="2" Grid.ColumnSpan="2" Name="Speichern" Content="Speichern" /> <Button Grid.Row="2" Grid.ColumnSpan="2" Name="Speichern" Content="Speichern" Command="{Binding SaveProjekt}" />
<TextBox Grid.Column="1" Grid.Row="0" Text="{Binding Projektnummer}" /> <TextBox Grid.Column="1" Grid.Row="0" Text="{Binding Projektnummer}" />
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Ort}" /> <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Ort}" />