EntityService should delegate more to repository.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NPoco;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
@@ -36,6 +36,7 @@ namespace Umbraco.Cms.Core.Persistence.Repositories
|
||||
|
||||
UmbracoObjectTypes GetObjectType(int id);
|
||||
UmbracoObjectTypes GetObjectType(Guid key);
|
||||
int ReserveId(Guid key);
|
||||
|
||||
IEnumerable<TreeEntityPath> GetAllPaths(Guid objectType, params int[] ids);
|
||||
IEnumerable<TreeEntityPath> GetAllPaths(Guid objectType, params Guid[] keys);
|
||||
|
||||
@@ -251,6 +251,38 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
return ObjectTypes.GetUmbracoObjectType(Database.ExecuteScalar<Guid>(sql));
|
||||
}
|
||||
|
||||
public int ReserveId(Guid key)
|
||||
{
|
||||
NodeDto node;
|
||||
|
||||
Sql<ISqlContext> sql = SqlContext.Sql()
|
||||
.Select<NodeDto>()
|
||||
.From<NodeDto>()
|
||||
.Where<NodeDto>(x => x.UniqueId == key && x.NodeObjectType == Cms.Core.Constants.ObjectTypes.IdReservation);
|
||||
|
||||
node = Database.SingleOrDefault<NodeDto>(sql);
|
||||
if (node != null)
|
||||
throw new InvalidOperationException("An identifier has already been reserved for this Udi.");
|
||||
|
||||
node = new NodeDto
|
||||
{
|
||||
UniqueId = key,
|
||||
Text = "RESERVED.ID",
|
||||
NodeObjectType = Cms.Core.Constants.ObjectTypes.IdReservation,
|
||||
|
||||
CreateDate = DateTime.Now,
|
||||
UserId = null,
|
||||
ParentId = -1,
|
||||
Level = 1,
|
||||
Path = "-1",
|
||||
SortOrder = 0,
|
||||
Trashed = false
|
||||
};
|
||||
Database.Insert(node);
|
||||
|
||||
return node.NodeId;
|
||||
}
|
||||
|
||||
public bool Exists(Guid key)
|
||||
{
|
||||
var sql = Sql().SelectCount().From<NodeDto>().Where<NodeDto>(x => x.UniqueId == key);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
@@ -398,13 +398,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
var sql = scope.SqlContext.Sql()
|
||||
.Select<NodeDto>(x => x.NodeObjectType)
|
||||
.From<NodeDto>()
|
||||
.Where<NodeDto>(x => x.NodeId == id);
|
||||
|
||||
var guid = scope.Database.ExecuteScalar<Guid>(sql);
|
||||
return ObjectTypes.GetUmbracoObjectType(guid);
|
||||
return _entityRepository.GetObjectType(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,13 +407,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
var sql = scope.SqlContext.Sql()
|
||||
.Select<NodeDto>(x => x.NodeObjectType)
|
||||
.From<NodeDto>()
|
||||
.Where<NodeDto>(x => x.UniqueId == key);
|
||||
|
||||
var guid = scope.Database.ExecuteScalar<Guid>(sql);
|
||||
return ObjectTypes.GetUmbracoObjectType(guid);
|
||||
return _entityRepository.GetObjectType(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -483,36 +471,10 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
/// <inheritdoc />
|
||||
public int ReserveId(Guid key)
|
||||
{
|
||||
NodeDto node;
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
using (ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
var sql = scope.SqlContext.Sql()
|
||||
.Select<NodeDto>()
|
||||
.From<NodeDto>()
|
||||
.Where<NodeDto>(x => x.UniqueId == key && x.NodeObjectType == Cms.Core.Constants.ObjectTypes.IdReservation);
|
||||
|
||||
node = scope.Database.SingleOrDefault<NodeDto>(sql);
|
||||
if (node != null)
|
||||
throw new InvalidOperationException("An identifier has already been reserved for this Udi.");
|
||||
|
||||
node = new NodeDto
|
||||
{
|
||||
UniqueId = key,
|
||||
Text = "RESERVED.ID",
|
||||
NodeObjectType = Cms.Core.Constants.ObjectTypes.IdReservation,
|
||||
|
||||
CreateDate = DateTime.Now,
|
||||
UserId = null,
|
||||
ParentId = -1,
|
||||
Level = 1,
|
||||
Path = "-1",
|
||||
SortOrder = 0,
|
||||
Trashed = false
|
||||
};
|
||||
scope.Database.Insert(node);
|
||||
scope.Complete();
|
||||
return _entityRepository.ReserveId(key);
|
||||
}
|
||||
return node.NodeId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user