Fetch membergroup by guid (#8496)

This commit is contained in:
Bjarne Fyrstenborg
2020-07-30 17:12:18 +02:00
committed by GitHub
parent dd8ddbae27
commit 312e2fa949
3 changed files with 21 additions and 3 deletions

View File

@@ -1,10 +1,18 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Umbraco.Core.Models;
namespace Umbraco.Core.Persistence.Repositories
{
public interface IMemberGroupRepository : IReadWriteQueryRepository<int, IMemberGroup>
{
/// <summary>
/// Gets a member group by it's uniqueId
/// </summary>
/// <param name="uniqueId"></param>
/// <returns></returns>
IMemberGroup Get(Guid uniqueId);
/// <summary>
/// Gets a member group by it's name
/// </summary>

View File

@@ -69,7 +69,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
protected override string GetBaseWhereClause()
{
return "umbracoNode.id = @id";
return $"{Constants.DatabaseSchema.Tables.Node}.id = @id";
}
protected override IEnumerable<string> GetDeleteClauses()
@@ -115,6 +115,16 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
entity.ResetDirtyProperties();
}
public IMemberGroup Get(Guid uniqueId)
{
var sql = GetBaseQuery(false);
sql.Where("umbracoNode.uniqueId = @uniqueId", new { uniqueId });
var dto = Database.Fetch<NodeDto>(SqlSyntax.SelectTop(sql, 1)).FirstOrDefault();
return dto == null ? null : MemberGroupFactory.BuildEntity(dto);
}
public IMemberGroup GetByName(string name)
{
return IsolatedCache.GetCacheItem<IMemberGroup>(

View File

@@ -74,7 +74,7 @@ namespace Umbraco.Core.Services.Implement
{
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
{
return _memberGroupRepository.GetMany().FirstOrDefault(x => x.Key == id);
return _memberGroupRepository.Get(id);
}
}