EntityService should delegate more to repository.

This commit is contained in:
Paul Johnson
2022-01-13 17:44:39 +00:00
parent 4a477c7378
commit 022042a0ce
3 changed files with 39 additions and 44 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;
}
}
}