Merge pull request #2164 from umbraco/temp-U4-10374
U4-10374 EntityService, ContentService and MediaService should use a …
This commit is contained in:
@@ -17,7 +17,7 @@ namespace Umbraco.Core.Models.Membership
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
public class User : Entity, IUser
|
||||
public class User : Entity, IUser, IProfile
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor for creating a new/empty user
|
||||
|
||||
@@ -684,7 +684,17 @@ namespace Umbraco.Core.Services
|
||||
// get query - if the id is System Root, then just get all
|
||||
var query = Query<IContent>.Builder;
|
||||
if (id != Constants.System.Root)
|
||||
query.Where(x => x.Path.SqlContains(string.Format(",{0},", id), TextColumnType.NVarchar));
|
||||
{
|
||||
var entityRepository = RepositoryFactory.CreateEntityRepository(uow);
|
||||
var contentPath = entityRepository.GetAllPaths(Constants.ObjectTypes.DocumentGuid, id).ToArray();
|
||||
if (contentPath.Length == 0)
|
||||
{
|
||||
totalChildren = 0;
|
||||
return Enumerable.Empty<IContent>();
|
||||
}
|
||||
query.Where(x => x.Path.SqlStartsWith(string.Format("{0},", contentPath[0]), TextColumnType.NVarchar));
|
||||
}
|
||||
|
||||
|
||||
// get filter
|
||||
IQuery<IContent> filterQuery = null;
|
||||
@@ -719,7 +729,16 @@ namespace Umbraco.Core.Services
|
||||
// get query - if the id is System Root, then just get all
|
||||
var query = Query<IContent>.Builder;
|
||||
if (id != Constants.System.Root)
|
||||
query.Where(x => x.Path.SqlContains(string.Format(",{0},", id), TextColumnType.NVarchar));
|
||||
{
|
||||
var entityRepository = RepositoryFactory.CreateEntityRepository(uow);
|
||||
var contentPath = entityRepository.GetAllPaths(Constants.ObjectTypes.DocumentGuid, id).ToArray();
|
||||
if (contentPath.Length == 0)
|
||||
{
|
||||
totalChildren = 0;
|
||||
return Enumerable.Empty<IContent>();
|
||||
}
|
||||
query.Where(x => x.Path.SqlStartsWith(string.Format("{0},", contentPath[0]), TextColumnType.NVarchar));
|
||||
}
|
||||
|
||||
return repository.GetPagedResultsByQuery(query, pageIndex, pageSize, out totalChildren, orderBy, orderDirection, orderBySystemField, filter);
|
||||
}
|
||||
@@ -1667,7 +1686,7 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
using (new WriteLock(Locker))
|
||||
{
|
||||
var nodeObjectType = new Guid(Constants.ObjectTypes.Document);
|
||||
var nodeObjectType = Constants.ObjectTypes.DocumentGuid;
|
||||
|
||||
using (var uow = UowProvider.GetUnitOfWork())
|
||||
{
|
||||
|
||||
@@ -348,11 +348,22 @@ namespace Umbraco.Core.Services
|
||||
using (var uow = UowProvider.GetUnitOfWork(readOnly:true))
|
||||
{
|
||||
var repository = RepositoryFactory.CreateEntityRepository(uow);
|
||||
|
||||
|
||||
var query = Query<IUmbracoEntity>.Builder;
|
||||
//if the id is System Root, then just get all
|
||||
if (id != Constants.System.Root)
|
||||
query.Where(x => x.Path.SqlContains(string.Format(",{0},", id), TextColumnType.NVarchar));
|
||||
{
|
||||
//lookup the path so we can use it in the prefix query below
|
||||
var itemPaths = repository.GetAllPaths(objectTypeId, id).ToArray();
|
||||
if (itemPaths.Length == 0)
|
||||
{
|
||||
totalRecords = 0;
|
||||
return Enumerable.Empty<IUmbracoEntity>();
|
||||
}
|
||||
var itemPath = itemPaths[0].Path;
|
||||
|
||||
query.Where(x => x.Path.SqlStartsWith(string.Format("{0},", itemPath), TextColumnType.NVarchar));
|
||||
}
|
||||
|
||||
IQuery<IUmbracoEntity> filterQuery = null;
|
||||
if (filter.IsNullOrWhiteSpace() == false)
|
||||
@@ -381,15 +392,30 @@ namespace Umbraco.Core.Services
|
||||
using (var uow = UowProvider.GetUnitOfWork(readOnly: true))
|
||||
{
|
||||
var repository = RepositoryFactory.CreateEntityRepository(uow);
|
||||
|
||||
|
||||
var query = Query<IUmbracoEntity>.Builder;
|
||||
if (idsA.All(x => x != Constants.System.Root))
|
||||
{
|
||||
//lookup the paths so we can use it in the prefix query below
|
||||
var itemPaths = repository.GetAllPaths(objectTypeId, idsA).ToArray();
|
||||
if (itemPaths.Length == 0)
|
||||
{
|
||||
totalRecords = 0;
|
||||
return Enumerable.Empty<IUmbracoEntity>();
|
||||
}
|
||||
|
||||
var clauses = new List<Expression<Func<IUmbracoEntity, bool>>>();
|
||||
foreach (var id in idsA)
|
||||
{
|
||||
var qid = id;
|
||||
clauses.Add(x => x.Path.SqlContains(string.Format(",{0},", qid), TextColumnType.NVarchar) || x.Path.SqlEndsWith(string.Format(",{0}", qid), TextColumnType.NVarchar));
|
||||
{
|
||||
//if the id is root then don't add any clauses
|
||||
if (id != Constants.System.Root)
|
||||
{
|
||||
var itemPath = itemPaths.FirstOrDefault(x => x.Id == id);
|
||||
if (itemPath == null) continue;
|
||||
var path = itemPath.Path;
|
||||
var qid = id;
|
||||
clauses.Add(x => x.Path.SqlStartsWith(string.Format("{0},", path), TextColumnType.NVarchar) || x.Path.SqlEndsWith(string.Format(",{0}", qid), TextColumnType.NVarchar));
|
||||
}
|
||||
}
|
||||
query.WhereAny(clauses);
|
||||
}
|
||||
@@ -442,7 +468,7 @@ namespace Umbraco.Core.Services
|
||||
return contents;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of descendents by the parents Id
|
||||
/// </summary>
|
||||
@@ -601,13 +627,13 @@ namespace Umbraco.Core.Services
|
||||
return repository.GetAllPaths(objectTypeId, keys);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of <see cref="IUmbracoEntity"/>
|
||||
/// Gets a collection of <see cref="T:Umbraco.Core.Models.EntityBase.IUmbracoEntity" />
|
||||
/// </summary>
|
||||
/// <param name="objectTypeId">Guid id of the UmbracoObjectType</param>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns>An enumerable list of <see cref="IUmbracoEntity"/> objects</returns>
|
||||
/// <returns>An enumerable list of <see cref="T:Umbraco.Core.Models.EntityBase.IUmbracoEntity" /> objects</returns>
|
||||
public virtual IEnumerable<IUmbracoEntity> GetAll(Guid objectTypeId, params int[] ids)
|
||||
{
|
||||
var umbracoObjectType = UmbracoObjectTypesExtensions.GetUmbracoObjectType(objectTypeId);
|
||||
|
||||
@@ -604,7 +604,14 @@ namespace Umbraco.Core.Services
|
||||
//if the id is System Root, then just get all
|
||||
if (id != Constants.System.Root)
|
||||
{
|
||||
query.Where(x => x.Path.SqlContains(string.Format(",{0},", id), TextColumnType.NVarchar));
|
||||
var entityRepository = RepositoryFactory.CreateEntityRepository(uow);
|
||||
var mediaPath = entityRepository.GetAllPaths(Constants.ObjectTypes.MediaGuid, id).ToArray();
|
||||
if (mediaPath.Length == 0)
|
||||
{
|
||||
totalChildren = 0;
|
||||
return Enumerable.Empty<IMedia>();
|
||||
}
|
||||
query.Where(x => x.Path.SqlStartsWith(string.Format("{0},", mediaPath[0]), TextColumnType.NVarchar));
|
||||
}
|
||||
IQuery<IMedia> filterQuery = null;
|
||||
if (filter.IsNullOrWhiteSpace() == false)
|
||||
|
||||
@@ -712,12 +712,11 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="id">Id of the User to retrieve</param>
|
||||
/// <returns><see cref="IProfile"/></returns>
|
||||
public IProfile GetProfileById(int id)
|
||||
{
|
||||
using (var uow = UowProvider.GetUnitOfWork(readOnly: true))
|
||||
{
|
||||
var repository = RepositoryFactory.CreateUserRepository(uow);
|
||||
return repository.GetProfile(id);
|
||||
}
|
||||
{
|
||||
//This is called a TON. Go get the full user from cache which should already be IProfile
|
||||
var fullUser = GetUserById(id);
|
||||
var asProfile = fullUser as IProfile;
|
||||
return asProfile ?? new UserProfile(fullUser.Id, fullUser.Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user