private void btnAddTask_Click(object sender, RoutedEventArgs e) { if (txtTaskName.Text.Trim().Length == 0) { MessageBox.Show("Please enter the task Name", "Invalid input", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (dtpDueDate.SelectedDateTime == default(DateTime)) { MessageBox.Show("Please select task's due date", "Invalid input", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } TasksHelper client = new TasksHelper(); var textRange = new TextRange(txtDesc.Document.ContentStart, txtDesc.Document.ContentEnd); try { client.CreateTask(user, event_.EventID, txtTaskName.Text.Trim(), textRange.Text.Trim(), dtpDueDate.SelectedDateTime); int currIdx = cboRole.SelectedIndex; cboRole.SelectedIndex = -1; cboRole.SelectedIndex = currIdx; MessageBox.Show("Operation Succeeded"); } catch (Exception ex) { MessageBox.Show("An Error have occured: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { client.Close(); } LoadTasks(); }