Files
Umbraco-CMS/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/IdKeyMapRepository.cs
Nikolaj Geisle cf2b9a0f21 V10: Move core services to core project (#12314)
* Move AuditService to core project

* Move two factor login service to core

* Move ServerRegistrationService to core

* Move BasicAuthService to Core project

* Move IdKeyMap to core project

* Added CacheInstructionService to the infrastructure namespace

* Move DataTypeService to core namespace

* Update CacheInstructionService.cs to use CoreScopeProvider

* Move core editors to core

* Move more Property editors and configuration

* Remove obsoleted constructors in internal classes

* Update PropertyEditors to use new ctors

* Fix propertyEditors to use new ctors

* Use the right property editor constructors

* add DI in the property method

* Update grid to use new ctor

* Fix non-assignment of variable

* Apply suggestions from code review

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Fix suggestions from code review

Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk>
Co-authored-by: Kevin Jump <kevin@thejumps.co.uk>
Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
2022-04-29 11:52:58 +02:00

54 lines
2.2 KiB
C#

using System;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Persistence.Repositories;
using Umbraco.Cms.Infrastructure.Scoping;
namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement;
public class IdKeyMapRepository : IIdKeyMapRepository
{
private readonly IScopeAccessor _scopeAccessor;
public IdKeyMapRepository(IScopeAccessor scopeAccessor)
{
_scopeAccessor = scopeAccessor;
}
public int? GetIdForKey(Guid key, UmbracoObjectTypes umbracoObjectType)
{
//if it's unknown don't include the nodeObjectType in the query
if (umbracoObjectType == UmbracoObjectTypes.Unknown)
{
return _scopeAccessor.AmbientScope?.Database.ExecuteScalar<int?>("SELECT id FROM umbracoNode WHERE uniqueId=@id", new { id = key});
}
else
{
return _scopeAccessor.AmbientScope?.Database.ExecuteScalar<int?>("SELECT id FROM umbracoNode WHERE uniqueId=@id AND (nodeObjectType=@type OR nodeObjectType=@reservation)",
new { id = key, type = GetNodeObjectTypeGuid(umbracoObjectType), reservation = Cms.Core.Constants.ObjectTypes.IdReservation });
}
}
public Guid? GetIdForKey(int id, UmbracoObjectTypes umbracoObjectType)
{
//if it's unknown don't include the nodeObjectType in the query
if (umbracoObjectType == UmbracoObjectTypes.Unknown)
{
return _scopeAccessor.AmbientScope?.Database.ExecuteScalar<Guid?>("SELECT uniqueId FROM umbracoNode WHERE id=@id", new { id });
}
else
{
return _scopeAccessor.AmbientScope?.Database.ExecuteScalar<Guid?>("SELECT uniqueId FROM umbracoNode WHERE id=@id AND (nodeObjectType=@type OR nodeObjectType=@reservation)",
new { id, type = GetNodeObjectTypeGuid(umbracoObjectType), reservation = Cms.Core.Constants.ObjectTypes.IdReservation });
}
}
private Guid GetNodeObjectTypeGuid(UmbracoObjectTypes umbracoObjectType)
{
var guid = umbracoObjectType.GetGuid();
if (guid == Guid.Empty)
throw new NotSupportedException("Unsupported object type (" + umbracoObjectType + ").");
return guid;
}
}