//Add a new word. private void btnOK_Click(object sender, RoutedEventArgs e) { int edit = 0; if (txtName.Text == "" || txtBritish.Text == "" || txtCanadian.Text == "" || txtAmerican.Text == "" || txtAustralian.Text == "") { MessageBox.Show("You should fill all fiels marked with '*'!", "Empty strings are not allowed", MessageBoxButton.OK, MessageBoxImage.Stop); return; } bool catChecked = false; foreach (CheckBox item in lstCategory.Items) { if (item.IsChecked == true) { catChecked = true; break; } } if (!catChecked) { MessageBox.Show("You should choose category.", "Choose category", MessageBoxButton.OK, MessageBoxImage.Stop); return; } Task.Run(new Action(() => { Dispatcher.Invoke(new Action(() => { if (!editForm) { int?id = _proxy.AddWord(txtName.Text, null, user); if (id == null) { MessageBox.Show("Something went wrong.", "Operation denied", MessageBoxButton.OK, MessageBoxImage.Stop); stMain.Visibility = Visibility.Visible; return; } edit = Convert.ToInt32(id); if (lPath.Content.ToString() != "...") { if (!_proxy.Upload(File.ReadAllBytes(lPath.Content.ToString()), $"{edit}{Path.GetExtension(lPath.Content.ToString())}", EngServRef.FilesType.WordsImages)) { MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop); _proxy.RemoveItem(edit, EngServRef.ServerData.Word); return; } _proxy.EditData(edit, $"{edit}{Path.GetExtension(lPath.Content.ToString())}", EngServRef.ServerData.Word, EngServRef.PropertyData.Imgpath); } string past = null, plural = null, pastTh = null; if (stPast.Visibility == Visibility.Visible) { past = txtPast.Text == "" ? null : txtPast.Text; } if (stPastParticiple.Visibility == Visibility.Visible) { pastTh = txtPastTh.Text == "" ? null : txtPastTh.Text; } if (stPlural.Visibility == Visibility.Visible) { plural = txtPlural.Text == "" ? null : txtPlural.Text; } _proxy.AddWordsForm(edit, past, plural, pastTh); _proxy.AddWordsTranscription(edit, txtBritish.Text, txtCanadian.Text, txtAmerican.Text, txtAustralian.Text); if (item != null) { _proxy.AddItemsWord(edit, Convert.ToInt32(item), data); } } else { _proxy.RemoveFullItemData(wordsId, EngServRef.ServerData.Translation); _proxy.RemoveFullItemData(wordsId, EngServRef.ServerData.Definition); _proxy.RemoveFullItemData(wordsId, EngServRef.ServerData.WordCategory); _proxy.RemoveFullItemData(wordsId, EngServRef.ServerData.Group); _proxy.RemoveFullItemData(wordsId, EngServRef.ServerData.Example); _proxy.EditData(wordsId, txtName.Text, EngServRef.ServerData.Word, EngServRef.PropertyData.Name); if (lPath.Content.ToString() != "...") { FormData.EditWords.Add(wordsId); string file = $"{wordsId}{Path.GetExtension(lPath.Content.ToString())}"; if (!_proxy.Upload(File.ReadAllBytes(lPath.Content.ToString()), file, EngServRef.FilesType.WordsImages)) { MessageBox.Show("This file is too large!\nPlease choose another file.", "Unable to upload", MessageBoxButton.OK, MessageBoxImage.Stop); return; } _proxy.EditData(wordsId, file, EngServRef.ServerData.Word, EngServRef.PropertyData.Imgpath); } _proxy.EditData(wordsId, txtPast.Text == ""? null: txtPast.Text, EngServRef.ServerData.Word, EngServRef.PropertyData.PastForm); _proxy.EditData(wordsId, txtPlural.Text == "" ? null : txtPlural.Text, EngServRef.ServerData.Word, EngServRef.PropertyData.PluralForm); _proxy.EditData(wordsId, txtPastTh.Text == "" ? null : txtPastTh.Text, EngServRef.ServerData.Word, EngServRef.PropertyData.PastThForm); _proxy.EditData(wordsId, txtBritish.Text, EngServRef.ServerData.Word, EngServRef.PropertyData.British); _proxy.EditData(wordsId, txtCanadian.Text, EngServRef.ServerData.Word, EngServRef.PropertyData.Canadian); _proxy.EditData(wordsId, txtAmerican.Text, EngServRef.ServerData.Word, EngServRef.PropertyData.American); _proxy.EditData(wordsId, txtAustralian.Text, EngServRef.ServerData.Word, EngServRef.PropertyData.Australian); edit = wordsId; } foreach (CheckBox item in lstCategory.Items) { if (item.IsChecked == true) { _proxy.AddItemDataAsync(edit, Convert.ToInt32(item.Tag), EngServRef.ServerData.WordCategory); } } foreach (CheckBox item in lstDefinitions?.Items) { if (item.IsChecked == true) { _proxy.AddItemDataAsync(edit, Convert.ToInt32(item.Tag), EngServRef.ServerData.Definition); } } foreach (CheckBox item in lstTranslations?.Items) { if (item.IsChecked == true) { _proxy.AddItemDataAsync(edit, Convert.ToInt32(item.Tag), EngServRef.ServerData.Translation); } } foreach (CheckBox item in lstGroups?.Items) { if (item.IsChecked == true) { _proxy.AddItemDataAsync(edit, Convert.ToInt32(item.Tag), EngServRef.ServerData.Group); } } foreach (CheckBox item in lstExamples?.Items) { if (item.IsChecked == true) { int itemsId = Convert.ToInt32(item.Tag); if (editForm && !_proxy.CheckExistence(item.Content.ToString(), EngServRef.ServerData.Example)) { itemsId = Convert.ToInt32(_proxy.AddData(item.Content.ToString(), EngServRef.ServerData.Example)); } _proxy.AddItemDataAsync(edit, itemsId, EngServRef.ServerData.Example); } } Close(); })); })); }