public void NewExamExecute(object param) { // New Button was pressed if (SelectedPatient != null) { SearchBoxText = ""; var v = new ExamView(); // new View //v.SelectedDate = System.DateTime.Now; var vm = new VMExamEdit(); // new ViewModel vm.Ex = new Examination { Ex_Patient = SelectedPatient.Pat_Id, Ex_Date = System.DateTime.Now }; vm.IstInEditMode = false; v.DataContext = vm; // view.DataContext = ViewModel v.ShowDialog(); if (v.DialogResult == true) // Save in Dialogbox clicked and inputs valid { using (KlinikDbEntities db = new KlinikDbEntities()) { db.Examinations.Add(vm.Ex); db.SaveChanges(); PropertyChanged(this, new PropertyChangedEventArgs("AllPatients")); } } else { PropertyChanged(this, new PropertyChangedEventArgs("AllPatients")); } } }
public void EditExecute(Object param) { if (SelectedExam != null) { var v = new ExamView(); //v.SelectedDate = SelectedExam.Ex_Date; var vm = new VMExamEdit(); vm.Ex = SelectedExam; vm.IstInEditMode = true; v.DataContext = vm; v.ShowDialog(); if (v.DialogResult == true) //save { using (KlinikDbEntities db = new KlinikDbEntities()) { vm.Ex.Examtype = null; //wegen include db.Entry(vm.Ex).State = EntityState.Modified; db.SaveChanges(); PropertyChanged(this, new PropertyChangedEventArgs("PatientExams")); } } else { PropertyChanged(this, new PropertyChangedEventArgs("PatientExams")); } } }