158 lines
3.5 KiB
C#
158 lines
3.5 KiB
C#
|
using BuechermarktClient.Models;
|
|||
|
using MongoDB.Driver;
|
|||
|
using System.ComponentModel;
|
|||
|
using System.Windows;
|
|||
|
|
|||
|
namespace BuechermarktClient
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Interaktionslogik für BookTypesEdit.xaml
|
|||
|
/// </summary>
|
|||
|
public partial class StudentsEdit : Window, INotifyPropertyChanged
|
|||
|
{
|
|||
|
private bool New = false;
|
|||
|
private Student Student = null;
|
|||
|
public string Forname
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return Student.Forname;
|
|||
|
}
|
|||
|
set {
|
|||
|
if(value != Student.Forname)
|
|||
|
{
|
|||
|
Student.Forname = value;
|
|||
|
OnPropertyChanged("Forname");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public string Lastname
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return Student.Lastname;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
if (value != Student.Lastname)
|
|||
|
{
|
|||
|
Student.Lastname = value;
|
|||
|
OnPropertyChanged("Lastname");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public string EMail
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return Student.EMail;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
if (value != Student.EMail)
|
|||
|
{
|
|||
|
Student.EMail = value;
|
|||
|
OnPropertyChanged("EMail");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public string PhoneNumber
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return Student.PhoneNumber;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
if (value != Student.PhoneNumber)
|
|||
|
{
|
|||
|
Student.PhoneNumber = value;
|
|||
|
OnPropertyChanged("PhoneNumber");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public string LabelId
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return Student.LabelId;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
if (value != Student.LabelId)
|
|||
|
{
|
|||
|
Student.LabelId = value;
|
|||
|
OnPropertyChanged("LabelId");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public string Form
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return Student.Form;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
if (value != Student.Form)
|
|||
|
{
|
|||
|
Student.Form = value;
|
|||
|
OnPropertyChanged("Form");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public event PropertyChangedEventHandler PropertyChanged;
|
|||
|
protected void OnPropertyChanged(string propertyName)
|
|||
|
{
|
|||
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|||
|
}
|
|||
|
|
|||
|
public StudentsEdit(Student student)
|
|||
|
{
|
|||
|
DataContext = this;
|
|||
|
if(student == null)
|
|||
|
{
|
|||
|
Student = new Student();
|
|||
|
New = true;
|
|||
|
} else
|
|||
|
{
|
|||
|
Student = student;
|
|||
|
}
|
|||
|
InitializeComponent();
|
|||
|
}
|
|||
|
|
|||
|
private void Save_Click(object sender, RoutedEventArgs e)
|
|||
|
{
|
|||
|
if(New)
|
|||
|
{
|
|||
|
MainWindow.StudentCollection.InsertOne(Student);
|
|||
|
} else
|
|||
|
{
|
|||
|
MainWindow.StudentCollection.FindOneAndUpdate(s => s.ID == Student.ID, Builders<Student>.Update
|
|||
|
.Set(s => s.Forname, Student.Forname)
|
|||
|
.Set(s => s.Lastname, Student.Lastname)
|
|||
|
.Set(s => s.EMail, Student.EMail)
|
|||
|
.Set(s => s.PhoneNumber, Student.PhoneNumber)
|
|||
|
.Set(s => s.LabelId, Student.LabelId)
|
|||
|
.Set(s=>s.Form, Student.Form));
|
|||
|
}
|
|||
|
Close();
|
|||
|
}
|
|||
|
|
|||
|
private void Delete_Click(object sender, RoutedEventArgs e)
|
|||
|
{
|
|||
|
if(Student.ID != null)
|
|||
|
{
|
|||
|
MainWindow.StudentCollection.DeleteOne(bt => bt.ID == Student.ID);
|
|||
|
}
|
|||
|
Close();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|