Files
Umbraco-CMS/src/Umbraco.Web/TagQuery.cs

101 lines
3.9 KiB
C#
Raw Normal View History

2018-06-29 19:52:40 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Composing;
2018-06-29 19:52:40 +02:00
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Services;
using Umbraco.Web.Models;
namespace Umbraco.Web
{
/// <summary>
2018-11-20 13:24:06 +01:00
/// Implements <see cref="ITagQuery"/>.
2018-06-29 19:52:40 +02:00
/// </summary>
public class TagQuery : ITagQuery
{
private readonly ITagService _tagService;
private readonly IPublishedContentQuery _contentQuery;
/// <summary>
2018-11-20 13:24:06 +01:00
/// Initializes a new instance of the <see cref="TagQuery"/> class.
2018-06-29 19:52:40 +02:00
/// </summary>
public TagQuery(ITagService tagService, IPublishedContentQuery contentQuery)
{
2018-11-20 13:24:06 +01:00
_tagService = tagService ?? throw new ArgumentNullException(nameof(tagService));
_contentQuery = contentQuery ?? throw new ArgumentNullException(nameof(contentQuery));
2018-06-29 19:52:40 +02:00
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<IPublishedContent> GetContentByTag(string tag, string group = null, string culture = null)
2018-06-29 19:52:40 +02:00
{
2018-11-20 13:24:06 +01:00
var ids = _tagService.GetTaggedContentByTag(tag, group, culture)
2018-06-29 19:52:40 +02:00
.Select(x => x.EntityId);
return _contentQuery.Content(ids)
.Where(x => x != null);
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<IPublishedContent> GetContentByTagGroup(string group, string culture = null)
2018-06-29 19:52:40 +02:00
{
2018-11-20 13:24:06 +01:00
var ids = _tagService.GetTaggedContentByTagGroup(group, culture)
2018-06-29 19:52:40 +02:00
.Select(x => x.EntityId);
return _contentQuery.Content(ids)
.Where(x => x != null);
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<IPublishedContent> GetMediaByTag(string tag, string group = null, string culture = null)
2018-06-29 19:52:40 +02:00
{
2018-11-20 13:24:06 +01:00
var ids = _tagService.GetTaggedMediaByTag(tag, group, culture)
2018-06-29 19:52:40 +02:00
.Select(x => x.EntityId);
return _contentQuery.Media(ids)
.Where(x => x != null);
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<IPublishedContent> GetMediaByTagGroup(string group, string culture = null)
2018-06-29 19:52:40 +02:00
{
2018-11-20 13:24:06 +01:00
var ids = _tagService.GetTaggedMediaByTagGroup(group, culture)
2018-06-29 19:52:40 +02:00
.Select(x => x.EntityId);
return _contentQuery.Media(ids)
.Where(x => x != null);
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<TagModel> GetAllTags(string group = null, string culture = null)
2018-06-29 19:52:40 +02:00
{
return Current.Mapper.Map<IEnumerable<TagModel>>(_tagService.GetAllTags(group, culture));
2018-06-29 19:52:40 +02:00
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<TagModel> GetAllContentTags(string group = null, string culture = null)
2018-06-29 19:52:40 +02:00
{
return Current.Mapper.Map<IEnumerable<TagModel>>(_tagService.GetAllContentTags(group, culture));
2018-06-29 19:52:40 +02:00
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<TagModel> GetAllMediaTags(string group = null, string culture = null)
2018-06-29 19:52:40 +02:00
{
return Current.Mapper.Map<IEnumerable<TagModel>>(_tagService.GetAllMediaTags(group, culture));
2018-06-29 19:52:40 +02:00
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<TagModel> GetAllMemberTags(string group = null, string culture = null)
2018-06-29 19:52:40 +02:00
{
return Current.Mapper.Map<IEnumerable<TagModel>>(_tagService.GetAllMemberTags(group, culture));
2018-06-29 19:52:40 +02:00
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<TagModel> GetTagsForProperty(int contentId, string propertyTypeAlias, string group = null, string culture = null)
2018-06-29 19:52:40 +02:00
{
return Current.Mapper.Map<IEnumerable<TagModel>>(_tagService.GetTagsForProperty(contentId, propertyTypeAlias, group, culture));
2018-06-29 19:52:40 +02:00
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<TagModel> GetTagsForEntity(int contentId, string group = null, string culture = null)
2018-06-29 19:52:40 +02:00
{
return Current.Mapper.Map<IEnumerable<TagModel>>(_tagService.GetTagsForEntity(contentId, group, culture));
2018-06-29 19:52:40 +02:00
}
}
}