using System; using System.Collections.Generic; using System.Linq; using Umbraco.Core.Mapping; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; using Umbraco.Web.Models; namespace Umbraco.Web { /// /// Implements . /// public class TagQuery : ITagQuery { private readonly ITagService _tagService; private readonly IPublishedContentQuery _contentQuery; private readonly UmbracoMapper _mapper; /// /// Initializes a new instance of the class. /// public TagQuery(ITagService tagService, IPublishedContentQuery contentQuery, UmbracoMapper mapper) { _tagService = tagService ?? throw new ArgumentNullException(nameof(tagService)); _contentQuery = contentQuery ?? throw new ArgumentNullException(nameof(contentQuery)); _mapper = mapper; } /// public IEnumerable GetContentByTag(string tag, string group = null, string culture = null) { var ids = _tagService.GetTaggedContentByTag(tag, group, culture) .Select(x => x.EntityId); return _contentQuery.Content(ids) .Where(x => x != null); } /// public IEnumerable GetContentByTagGroup(string group, string culture = null) { var ids = _tagService.GetTaggedContentByTagGroup(group, culture) .Select(x => x.EntityId); return _contentQuery.Content(ids) .Where(x => x != null); } /// public IEnumerable GetMediaByTag(string tag, string group = null, string culture = null) { var ids = _tagService.GetTaggedMediaByTag(tag, group, culture) .Select(x => x.EntityId); return _contentQuery.Media(ids) .Where(x => x != null); } /// public IEnumerable GetMediaByTagGroup(string group, string culture = null) { var ids = _tagService.GetTaggedMediaByTagGroup(group, culture) .Select(x => x.EntityId); return _contentQuery.Media(ids) .Where(x => x != null); } /// public IEnumerable GetAllTags(string group = null, string culture = null) { return _mapper.MapEnumerable(_tagService.GetAllTags(group, culture)); } /// public IEnumerable GetAllContentTags(string group = null, string culture = null) { return _mapper.MapEnumerable(_tagService.GetAllContentTags(group, culture)); } /// public IEnumerable GetAllMediaTags(string group = null, string culture = null) { return _mapper.MapEnumerable(_tagService.GetAllMediaTags(group, culture)); } /// public IEnumerable GetAllMemberTags(string group = null, string culture = null) { return _mapper.MapEnumerable(_tagService.GetAllMemberTags(group, culture)); } /// public IEnumerable GetTagsForProperty(int contentId, string propertyTypeAlias, string group = null, string culture = null) { return _mapper.MapEnumerable(_tagService.GetTagsForProperty(contentId, propertyTypeAlias, group, culture)); } /// public IEnumerable GetTagsForEntity(int contentId, string group = null, string culture = null) { return _mapper.MapEnumerable(_tagService.GetTagsForEntity(contentId, group, culture)); } } }