private void AddNewTag() { if (TagSearchDataContext.FullSearchText.Length > 20) { MessageBox.Show("Tag name cannot be longer than 20 characters (including space).", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); return; } // Check if this tag has been deleted before, then prompt the user to see if we should restore or replace it. var newTag = DeletedTags.SingleOrDefault(t => t.Name == TagSearchDataContext.FullSearchText); if (newTag == null) { newTag = Context.Tags.SingleOrDefault(t => t.DateDeleted != null && t.Name == TagSearchDataContext.FullSearchText); } if (newTag != null) { var result = MessageBox.Show($"The tag [{newTag.Name}] was previously deleted. You can either restore this tag and all Omni associations, " + "or replace the deleted tag with a brand new one.\n\nWhen this tag is undeleted, do you want to restore " + "Omni associations?", "Confirm Restore", MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Yes); if (result == MessageBoxResult.Cancel) { return; } else if (result == MessageBoxResult.No) { newTag.Omnis.Clear(); Context.Tags.Remove(newTag); newTag = null; } DeletedTags.Remove(newTag); } if (newTag == null) { newTag = new Tag { Name = TagSearchDataContext.FullSearchText, }; AddedTags.Add(newTag); } newTag.DateDeleted = null; newTag.LastModifiedDate = DateTime.Now; newTag.IsVerified = true; newTag.ManuallyVerified = true; AllTags.Add(newTag); TagSearchDataContext.FullSearchText = String.Empty; SelectedTag = newTag; ChangesMade = true; }
private void AddTag() { if (TagSearchText.IsEmpty()) { return; } if (TagSearchText.Length > 20) { MessageBox.Show("Tag name cannot be longer than 20 characters (including space).", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); return; } if (OmniTags.Any(t => t.Name.Equals(TagSearchText, StringComparison.CurrentCultureIgnoreCase))) { MessageBox.Show($"This Omni is already associated with the \"{TagSearchText}\" tag.", "Warning", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); return; } var tag = Context.Tags.SingleOrDefault(t => t.Name == TagSearchText); if (tag == null) { tag = new Tag { Name = TagSearchText, Description = null, IsVerified = false, DateCreated = DateTime.Now, LastModifiedDate = DateTime.Now }; AddedTags.Add(tag); } tag.DateDeleted = null; // undelete the tag (if it was in the DB but deleted) var buttonVm = new TagButtonViewModel(tag); OmniTags.Add(tag); ImageButtons.Add(buttonVm); TagSearchText = ""; ChangesMade = true; }