//Add a new grammar. private void btnOK_Click(object sender, RoutedEventArgs e) { int edit = 0; if (txtName.Text == "") { MessageBox.Show("You should fill all fiels marked with '*'!", "Empty strings are not allowed", MessageBoxButton.OK, MessageBoxImage.Stop); return; } bool ruleChecked = false; foreach (CheckBox item in lstRules.Items) { if (item.IsChecked == true) { ruleChecked = true; break; } } if (!ruleChecked) { MessageBox.Show("You should add rules.", "Choose rule", MessageBoxButton.OK, MessageBoxImage.Stop); return; } Task.Run(new Action(() => { Dispatcher.Invoke(new Action(() => { if (grammarId == null) { int?id = _proxy.AddGrammar(txtName.Text, txtDescription.Text == "" ? null : txtDescription.Text); if (id == null) { MessageBox.Show("Something went wrong.", "Operation denied", MessageBoxButton.OK, MessageBoxImage.Stop); stMain.Visibility = Visibility.Visible; return; } edit = Convert.ToInt32(id); } else { _proxy.RemoveFullItemData(Convert.ToInt32(grammarId), EngServRef.ServerData.Rule); _proxy.RemoveFullItemData(Convert.ToInt32(grammarId), EngServRef.ServerData.GrammarExample); _proxy.RemoveFullItemData(Convert.ToInt32(grammarId), EngServRef.ServerData.GrammarException); _proxy.EditData(Convert.ToInt32(grammarId), txtName.Text, EngServRef.ServerData.Grammar, EngServRef.PropertyData.Name); _proxy.EditData(Convert.ToInt32(grammarId), txtDescription.Text == "" ? null : txtDescription.Text, EngServRef.ServerData.Grammar, EngServRef.PropertyData.Description); edit = Convert.ToInt32(grammarId); } foreach (CheckBox item in lstRules?.Items) { if (item.IsChecked == true) { _proxy.AddItemDataAsync(edit, Convert.ToInt32(item.Tag), EngServRef.ServerData.Rule); } } foreach (CheckBox item in lstExceptions?.Items) { if (item.IsChecked == true) { _proxy.AddItemDataAsync(edit, Convert.ToInt32(item.Tag), EngServRef.ServerData.GrammarException); } } foreach (CheckBox item in lstExamples?.Items) { if (item.IsChecked == true) { _proxy.AddItemDataAsync(edit, Convert.ToInt32(item.Tag), EngServRef.ServerData.GrammarExample); } } Close(); })); })); }