private void btnCreateDiary_Click(object sender, RoutedEventArgs e) { try { //create a instance of controlling controlling con = new controlling(); //Create a new diary if (string.IsNullOrEmpty(txtDiaryName.Text)) { throw new Exception("Name missing"); } else if (con.Diary_Exist(txtDiaryName.Text)) { throw new Exception($"Diary with the name {txtDiaryName.Text} already exists"); } else { int id = con.Create_Diary(txtDiaryName.Text, currentUserID); if (id == -1) { throw new Exception("Could not create the diary"); } con.Show_SearchWindow(id); this.Close(); } } catch (Exception error) { MessageBox.Show(error.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void Button_Click(object sender, RoutedEventArgs e) { //create a instance of controlling controlling con = new controlling(); //Get id of the diary if (cmbDiaries.SelectedItem != null) { e_Tagebuch_Context DB = new e_Tagebuch_Context(); var diary = DB.Diaries.FirstOrDefault(d => d.Name == cmbDiaries.SelectedItem.ToString()); con.Show_SearchWindow(diary.DiaryID); this.Close (); } else { MessageBox.Show("No diary is selected", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } }