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 DeleteTag(object obj) { var ibvm = obj as TagButtonViewModel; if (ibvm == null) { return; } OmniTags.Remove(ibvm.CurrentTag); ImageButtons.Remove(ibvm); if (!AddedTags.Remove(ibvm.CurrentTag)) { DeletedTags.Add(ibvm.CurrentTag); } ChangesMade = true; }
private void SaveTagInfo() { if (!ChangesMade) { return; } if ((SelectedTag != null) && (SelectedTag.Name != SelectedTagName)) { SelectedTag.Name = SelectedTagName; SelectedTag.LastModifiedDate = DateTime.Now; } if ((SelectedTag != null) && (SelectedTag.Description != SelectedTagDescription)) { SelectedTag.Description = SelectedTagDescription; SelectedTag.LastModifiedDate = DateTime.Now; } if ((SelectedTag != null) && ((SelectedTag.IsVerified != IsSelectedTagVerified) || (SelectedTag.ManuallyVerified != IsSelectedTagManuallyVerified))) { SelectedTag.IsVerified = IsSelectedTagVerified ?? false; SelectedTag.ManuallyVerified = IsSelectedTagManuallyVerified ?? false; SelectedTag.LastModifiedDate = DateTime.Now; } foreach (var tag in AddedTags) { tag.LastModifiedDate = DateTime.Now; } foreach (var tag in DeletedTags) { tag.LastModifiedDate = DateTime.Now; } // "Hard save" all changes made to all tags into the database. Context.Tags.AddRange(AddedTags); Context.SaveChanges(); SelectedTagLastUpdatedTime = DateTime.Now; AddedTags.Clear(); DeletedTags.Clear(); ChangesMade = false; OnDataChanged(); }
private void DeleteSelectedTag() { var result = MessageBox.Show($"Are you sure you want to delete the [{SelectedTag.Name}] tag? It will be disassociated from any Omnis.", $"Delete Tag [{SelectedTag.Name}]", MessageBoxButton.YesNo); if (result == MessageBoxResult.No) { return; } if (!AddedTags.Remove(SelectedTag)) { DeletedTags.Add(SelectedTag); } SelectedTag.DateDeleted = DateTime.Now; AllTags.Remove(SelectedTag); SelectedTag = null; ChangesMade = true; }
private void SaveOmni() { if (!ChangesMade) { return; } if (OmniTags.Count == 0) { var result = MessageBox.Show("This Omni is not associated with any tags. This will prevent it from " + "being listed if any tag filters are chosen during searches.\n\n" + "Are you sure you want to continue " + "without associating a tag?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No); if (result == MessageBoxResult.No) { return; } } if (CurrentOmni.Summary != OmniSummary) { if (OmniSummary.Length > 100) { MessageBox.Show("Omni summary cannot be longer than 100 characters (including spaces). The current " + $"length of the summary is {OmniSummary.Length} characters.", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); return; } CurrentOmni.Summary = OmniSummary; CurrentOmni.LastModifiedDate = DateTime.Now; } if (CurrentOmni.Description != OmniDescription) { CurrentOmni.Description = OmniDescription; CurrentOmni.LastModifiedDate = DateTime.Now; foreach (var imageFileName in CurrentOmni.Images.Select(i => i.FileName).ToList()) { if (!CurrentOmni.Description.Contains(imageFileName.Replace(" ", "%20"))) { var img = Context.Images.Single(i => i.FileName == imageFileName); Context.Images.Remove(img); } } } if (!OmniTags.IsEqualTo(CurrentOmni.Tags)) { CurrentOmni.Tags = OmniTags; CurrentOmni.LastModifiedDate = DateTime.Now; } foreach (var tag in AddedTags) { Context.Tags.Add(tag); CurrentOmni.LastModifiedDate = DateTime.Now; if (tag.Omnis.Count >= _autoVerifyThreshold) { tag.IsVerified = true; } } AddedTags.Clear(); foreach (var tag in DeletedTags) { if ((!tag.ManuallyVerified) && (tag.Omnis.Count < _autoVerifyThreshold)) { tag.IsVerified = false; } // If an unverified tag isn't being used, we delete it since the user hasn't marked the tag as important. if ((!tag.ManuallyVerified) && (tag.Omnis.Count == 1)) // use 1 here to represent the current tag and no others { tag.DateDeleted = DateTime.Now; } CurrentOmni.LastModifiedDate = DateTime.Now; } DeletedTags.Clear(); if (_isNewOmni) { Context.Omnis.Add(CurrentOmni); } Context.SaveChanges(); foreach (var tag in OmniTags) { if (tag.Omnis.Count >= _autoVerifyThreshold) { tag.IsVerified = true; } } Context.SaveChanges(); ChangesMade = false; _isNewOmni = false; CurrentOmniLastUpdatedTime = CurrentOmni.LastModifiedDate; OnDataChanged(); }