membergroup made static

This commit is contained in:
Ismail Mayat
2018-06-29 11:52:12 +01:00
parent de2322e384
commit 3c8a870dfa
3 changed files with 67 additions and 69 deletions

View File

@@ -1,55 +1,55 @@
using System;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Dtos;
namespace Umbraco.Core.Persistence.Factories
{
internal class DictionaryTranslationFactory
{
private readonly Guid _uniqueId;
public DictionaryTranslationFactory(Guid uniqueId)
{
_uniqueId = uniqueId;
}
#region Implementation of IEntityFactory<DictionaryTranslation,LanguageTextDto>
public IDictionaryTranslation BuildEntity(LanguageTextDto dto)
{
var item = new DictionaryTranslation(dto.LanguageId, dto.Value, _uniqueId);
try
{
item.DisableChangeTracking();
item.Id = dto.PrimaryKey;
// reset dirty initial properties (U4-1946)
item.ResetDirtyProperties(false);
return item;
}
finally
{
item.EnableChangeTracking();
}
}
public LanguageTextDto BuildDto(IDictionaryTranslation entity)
{
var text = new LanguageTextDto
{
LanguageId = entity.LanguageId,
UniqueId = _uniqueId,
Value = entity.Value
};
if (entity.HasIdentity)
text.PrimaryKey = entity.Id;
return text;
}
#endregion
}
}
using System;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Dtos;
namespace Umbraco.Core.Persistence.Factories
{
internal class DictionaryTranslationFactory
{
private readonly Guid _uniqueId;
public DictionaryTranslationFactory(Guid uniqueId)
{
_uniqueId = uniqueId;
}
#region Implementation of IEntityFactory<DictionaryTranslation,LanguageTextDto>
public IDictionaryTranslation BuildEntity(LanguageTextDto dto)
{
var item = new DictionaryTranslation(dto.LanguageId, dto.Value, _uniqueId);
try
{
item.DisableChangeTracking();
item.Id = dto.PrimaryKey;
// reset dirty initial properties (U4-1946)
item.ResetDirtyProperties(false);
return item;
}
finally
{
item.EnableChangeTracking();
}
}
public LanguageTextDto BuildDto(IDictionaryTranslation entity)
{
var text = new LanguageTextDto
{
LanguageId = entity.LanguageId,
UniqueId = _uniqueId,
Value = entity.Value
};
if (entity.HasIdentity)
text.PrimaryKey = entity.Id;
return text;
}
#endregion
}
}

View File

@@ -4,19 +4,19 @@ using Umbraco.Core.Persistence.Dtos;
namespace Umbraco.Core.Persistence.Factories
{
internal class MemberGroupFactory
internal static class MemberGroupFactory
{
private readonly Guid _nodeObjectTypeId;
private static readonly Guid _nodeObjectTypeId;
public MemberGroupFactory()
static MemberGroupFactory()
{
_nodeObjectTypeId = Constants.ObjectTypes.MemberGroup;
}
#region Implementation of IEntityFactory<ITemplate,TemplateDto>
public IMemberGroup BuildEntity(NodeDto dto)
public static IMemberGroup BuildEntity(NodeDto dto)
{
var group = new MemberGroup();
@@ -39,7 +39,7 @@ namespace Umbraco.Core.Persistence.Factories
}
}
public NodeDto BuildDto(IMemberGroup entity)
public static NodeDto BuildDto(IMemberGroup entity)
{
var dto = new NodeDto
{

View File

@@ -19,8 +19,6 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
: base(scopeAccessor, cache, logger)
{ }
private readonly MemberGroupFactory _modelFactory = new MemberGroupFactory();
protected override IMemberGroup PerformGet(int id)
{
var sql = GetBaseQuery(false);
@@ -28,7 +26,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
var dto = Database.Fetch<NodeDto>(SqlSyntax.SelectTop(sql, 1)).FirstOrDefault();
return dto == null ? null : _modelFactory.BuildEntity(dto);
return dto == null ? null : MemberGroupFactory.BuildEntity(dto);
}
protected override IEnumerable<IMemberGroup> PerformGetAll(params int[] ids)
@@ -41,7 +39,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
if (ids.Any())
sql.Where("umbracoNode.id in (@ids)", new { /*ids =*/ ids });
return Database.Fetch<NodeDto>(sql).Select(x => _modelFactory.BuildEntity(x));
return Database.Fetch<NodeDto>(sql).Select(x => MemberGroupFactory.BuildEntity(x));
}
protected override IEnumerable<IMemberGroup> PerformGetByQuery(IQuery<IMemberGroup> query)
@@ -50,7 +48,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
var translator = new SqlTranslator<IMemberGroup>(sqlClause, query);
var sql = translator.Translate();
return Database.Fetch<NodeDto>(sql).Select(x => _modelFactory.BuildEntity(x));
return Database.Fetch<NodeDto>(sql).Select(x => MemberGroupFactory.BuildEntity(x));
}
protected override Sql<ISqlContext> GetBaseQuery(bool isCount)
@@ -95,7 +93,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
//Save to db
var group = (MemberGroup)entity;
group.AddingEntity();
var dto = _modelFactory.BuildDto(group);
var dto = MemberGroupFactory.BuildDto(group);
var o = Database.IsNew(dto) ? Convert.ToInt32(Database.Insert(dto)) : Database.Update(dto);
group.Id = dto.NodeId; //Set Id on entity to ensure an Id is set
@@ -109,7 +107,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
protected override void PersistUpdatedItem(IMemberGroup entity)
{
var dto = _modelFactory.BuildDto(entity);
var dto = MemberGroupFactory.BuildDto(entity);
Database.Update(dto);
@@ -164,7 +162,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
return Database.Fetch<NodeDto>(sql)
.DistinctBy(dto => dto.NodeId)
.Select(x => _modelFactory.BuildEntity(x));
.Select(x => MemberGroupFactory.BuildEntity(x));
}
public IEnumerable<IMemberGroup> GetMemberGroupsForMember(string username)
@@ -181,7 +179,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
return Database.Fetch<NodeDto>(sql)
.DistinctBy(dto => dto.NodeId)
.Select(x => _modelFactory.BuildEntity(x));
.Select(x => MemberGroupFactory.BuildEntity(x));
}
public int[] GetMemberIds(string[] usernames)