private void TagContentItem(TagsPartRecord tagsPartRecord, string tagName) { var tagRecord = GetTagByName(tagName); var tagsContentItems = new ContentTagRecord { TagsPartRecord = tagsPartRecord, TagRecord = tagRecord }; _contentTagRepository.Create(tagsContentItems); }
private void TagContentItem(TagsPartRecord tagsPartRecord, string tagName) { var tagPart = _orchardServices.ContentManager.Get <TagsPart>(tagsPartRecord.Id, VersionOptions.Latest); tagPart.CurrentTags = tagPart.CurrentTags.Concat(new [] { tagName }); var tagRecord = GetTagByName(tagName); var tagsContentItems = new ContentTagRecord { TagsPartRecord = tagsPartRecord, TagRecord = tagRecord }; _contentTagRepository.Create(tagsContentItems); }
public void UpdateTag(int tagId, string tagName) { _authorizationService.CheckAccess(Permissions.ManageTags, _orchardServices.WorkContext.CurrentUser, null); if (String.IsNullOrEmpty(tagName)) { _notifier.Warning(T("Couldn't rename tag: name was empty")); return; } var tagRecord = GetTagByName(tagName); // new tag name already existing => merge if (tagRecord != null) { // If updating ourselves, ignore if (tagRecord.Id == tagId) { return; } var tagsContentItems = _contentTagRepository.Fetch(x => x.TagRecord.Id == tagId); // get contentItems already tagged with the existing one var taggedContentItems = GetTaggedContentItems(tagRecord.Id); foreach (var tagContentItem in tagsContentItems) { ContentTagRecord item = tagContentItem; if (!taggedContentItems.Any(c => c.ContentItem.Id == item.TagsPartRecord.Id)) { TagContentItem(tagContentItem.TagsPartRecord, tagName); } _contentTagRepository.Delete(tagContentItem); } _tagRepository.Delete(GetTag(tagId)); return; } // Create new tag tagRecord = _tagRepository.Get(tagId); tagRecord.TagName = tagName; }
public void UpdateTag(int tagId, string tagName) { _authorizationService.CheckAccess(Permissions.ManageTags, _tomeltServices.WorkContext.CurrentUser, null); if (String.IsNullOrEmpty(tagName)) { _notifier.Warning(T("Couldn't rename tag: name was empty")); return; } var tagRecord = GetTagByName(tagName); // new tag name already existing => merge if (tagRecord != null && tagRecord.Id != tagId) { var tagsContentItems = _contentTagRepository.Fetch(x => x.TagRecord.Id == tagId); // get contentItems already tagged with the existing one var taggedContentItems = GetTaggedContentItems(tagRecord.Id).ToArray(); var oldTag = GetTag(tagId); foreach (var tagContentItem in tagsContentItems) { ContentTagRecord item = tagContentItem; // does the content item already have the new tag ? if (taggedContentItems.All(c => c.ContentItem.Id != item.TagsPartRecord.Id)) { TagContentItem(tagContentItem.TagsPartRecord, tagName); } UntagContentItem(tagContentItem.TagsPartRecord, oldTag.TagName); _contentTagRepository.Delete(tagContentItem); } _tagRepository.Delete(oldTag); return; } // Create new tag tagRecord = _tagRepository.Get(tagId); tagRecord.TagName = tagName; }