back ports entity service updates
This commit is contained in:
@@ -39,6 +39,27 @@ namespace Umbraco.Core.Services
|
||||
};
|
||||
}
|
||||
|
||||
public IUmbracoEntity GetByKey(Guid key, bool loadBaseType = true)
|
||||
{
|
||||
if (loadBaseType)
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreateEntityRepository(_uowProvider.GetUnitOfWork()))
|
||||
{
|
||||
return repository.GetByKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
//SD: TODO: Need to enable this at some stage ... just need to ask Morten what the deal is with what this does.
|
||||
throw new NotSupportedException();
|
||||
|
||||
//var objectType = GetObjectType(key);
|
||||
//var entityType = GetEntityType(objectType);
|
||||
//var typeFullName = entityType.FullName;
|
||||
//var entity = _supportedObjectTypes[typeFullName].Item2(id);
|
||||
|
||||
//return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an UmbracoEntity by its Id, and optionally loads the complete object graph.
|
||||
/// </summary>
|
||||
@@ -66,6 +87,27 @@ namespace Umbraco.Core.Services
|
||||
return entity;
|
||||
}
|
||||
|
||||
public IUmbracoEntity GetByKey(Guid key, UmbracoObjectTypes umbracoObjectType, bool loadBaseType = true)
|
||||
{
|
||||
if (loadBaseType)
|
||||
{
|
||||
var objectTypeId = umbracoObjectType.GetGuid();
|
||||
using (var repository = _repositoryFactory.CreateEntityRepository(_uowProvider.GetUnitOfWork()))
|
||||
{
|
||||
return repository.GetByKey(key, objectTypeId);
|
||||
}
|
||||
}
|
||||
|
||||
//SD: TODO: Need to enable this at some stage ... just need to ask Morten what the deal is with what this does.
|
||||
throw new NotSupportedException();
|
||||
|
||||
//var entityType = GetEntityType(umbracoObjectType);
|
||||
//var typeFullName = entityType.FullName;
|
||||
//var entity = _supportedObjectTypes[typeFullName].Item2(id);
|
||||
|
||||
//return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an UmbracoEntity by its Id and UmbracoObjectType, and optionally loads the complete object graph.
|
||||
/// </summary>
|
||||
@@ -94,6 +136,11 @@ namespace Umbraco.Core.Services
|
||||
return entity;
|
||||
}
|
||||
|
||||
public IUmbracoEntity GetByKey<T>(Guid key, bool loadBaseType = true) where T : IUmbracoEntity
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an UmbracoEntity by its Id and specified Type. Optionally loads the complete object graph.
|
||||
/// </summary>
|
||||
@@ -255,12 +302,12 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="IUmbracoEntity"/> objects</returns>
|
||||
public virtual IEnumerable<IUmbracoEntity> GetAll<T>() where T : IUmbracoEntity
|
||||
{
|
||||
var typeFullName = typeof (T).FullName;
|
||||
var typeFullName = typeof(T).FullName;
|
||||
Mandate.That<NotSupportedException>(_supportedObjectTypes.ContainsKey(typeFullName), () =>
|
||||
{
|
||||
throw new NotSupportedException
|
||||
("The passed in type is not supported");
|
||||
});
|
||||
{
|
||||
throw new NotSupportedException
|
||||
("The passed in type is not supported");
|
||||
});
|
||||
var objectType = _supportedObjectTypes[typeFullName].Item1;
|
||||
|
||||
return GetAll(objectType);
|
||||
@@ -326,6 +373,22 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the UmbracoObjectType from the integer id of an IUmbracoEntity.
|
||||
/// </summary>
|
||||
/// <param name="key">Unique Id of the entity</param>
|
||||
/// <returns><see cref="UmbracoObjectTypes"/></returns>
|
||||
public virtual UmbracoObjectTypes GetObjectType(Guid key)
|
||||
{
|
||||
using (var uow = _uowProvider.GetUnitOfWork())
|
||||
{
|
||||
var sql = new Sql().Select("nodeObjectType").From<NodeDto>().Where<NodeDto>(x => x.UniqueId == key);
|
||||
var nodeObjectTypeId = uow.Database.ExecuteScalar<string>(sql);
|
||||
var objectTypeId = new Guid(nodeObjectTypeId);
|
||||
return UmbracoObjectTypesExtensions.GetUmbracoObjectType(objectTypeId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the UmbracoObjectType from an IUmbracoEntity.
|
||||
/// </summary>
|
||||
@@ -367,7 +430,7 @@ namespace Umbraco.Core.Services
|
||||
if (attribute == null)
|
||||
throw new NullReferenceException("The passed in UmbracoObjectType does not contain an UmbracoObjectTypeAttribute, which is used to retrieve the Type.");
|
||||
|
||||
if(attribute.ModelType == null)
|
||||
if (attribute.ModelType == null)
|
||||
throw new NullReferenceException("The passed in UmbracoObjectType does not contain a Type definition");
|
||||
|
||||
return attribute.ModelType;
|
||||
|
||||
Reference in New Issue
Block a user