using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Membership;
namespace Umbraco.Core.Services
{
///
/// Content service extension methods
///
public static class ContentServiceExtensions
{
public static IEnumerable GetByIds(this IContentService contentService, IEnumerable ids)
{
var guids = new List();
foreach (var udi in ids)
{
var guidUdi = udi as GuidUdi;
if (guidUdi == null)
throw new InvalidOperationException("The UDI provided isn't of type " + typeof(GuidUdi) + " which is required by content");
guids.Add(guidUdi);
}
return contentService.GetByIds(guids.Select(x => x.Guid));
}
///
/// Method to create an IContent object based on the Udi of a parent
///
///
///
///
///
///
///
public static IContent CreateContent(this IContentService contentService, string name, Udi parentId, string mediaTypeAlias, int userId = 0)
{
var guidUdi = parentId as GuidUdi;
if (guidUdi == null)
throw new InvalidOperationException("The UDI provided isn't of type " + typeof(GuidUdi) + " which is required by content");
var parent = contentService.GetById(guidUdi.Guid);
return contentService.Create(name, parent, mediaTypeAlias, userId);
}
///
/// Remove all permissions for this user for all nodes
///
///
///
public static void RemoveContentPermissions(this IContentService contentService, int contentId)
{
contentService.SetPermissions(new EntityPermissionSet(contentId, new EntityPermissionCollection()));
}
///
/// Returns true if there is any content in the recycle bin
///
///
///
public static bool RecycleBinSmells(this IContentService contentService)
{
return contentService.CountChildren(Constants.System.RecycleBinContent) > 0;
}
///
/// Returns true if there is any media in the recycle bin
///
///
///
public static bool RecycleBinSmells(this IMediaService mediaService)
{
return mediaService.CountChildren(Constants.System.RecycleBinMedia) > 0;
}
}
}