server registration now static

This commit is contained in:
Ismail Mayat
2018-06-29 12:09:47 +01:00
parent 69a103ce3d
commit 4f4dc922e0
2 changed files with 38 additions and 41 deletions

View File

@@ -1,34 +1,34 @@
using Umbraco.Core.Models; using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Dtos; using Umbraco.Core.Persistence.Dtos;
namespace Umbraco.Core.Persistence.Factories namespace Umbraco.Core.Persistence.Factories
{ {
internal class ServerRegistrationFactory internal static class ServerRegistrationFactory
{ {
public ServerRegistration BuildEntity(ServerRegistrationDto dto) public static ServerRegistration BuildEntity(ServerRegistrationDto dto)
{ {
var model = new ServerRegistration(dto.Id, dto.ServerAddress, dto.ServerIdentity, dto.DateRegistered, dto.DateAccessed, dto.IsActive, dto.IsMaster); var model = new ServerRegistration(dto.Id, dto.ServerAddress, dto.ServerIdentity, dto.DateRegistered, dto.DateAccessed, dto.IsActive, dto.IsMaster);
// reset dirty initial properties (U4-1946) // reset dirty initial properties (U4-1946)
model.ResetDirtyProperties(false); model.ResetDirtyProperties(false);
return model; return model;
} }
public ServerRegistrationDto BuildDto(IServerRegistration entity) public static ServerRegistrationDto BuildDto(IServerRegistration entity)
{ {
var dto = new ServerRegistrationDto var dto = new ServerRegistrationDto
{ {
ServerAddress = entity.ServerAddress, ServerAddress = entity.ServerAddress,
DateRegistered = entity.CreateDate, DateRegistered = entity.CreateDate,
IsActive = entity.IsActive, IsActive = entity.IsActive,
IsMaster = ((ServerRegistration) entity).IsMaster, IsMaster = ((ServerRegistration) entity).IsMaster,
DateAccessed = entity.UpdateDate, DateAccessed = entity.UpdateDate,
ServerIdentity = entity.ServerIdentity ServerIdentity = entity.ServerIdentity
}; };
if (entity.HasIdentity) if (entity.HasIdentity)
dto.Id = entity.Id; dto.Id = entity.Id;
return dto; return dto;
} }
} }
} }

View File

@@ -56,9 +56,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
protected override IEnumerable<IServerRegistration> PerformGetAll(params int[] ids) protected override IEnumerable<IServerRegistration> PerformGetAll(params int[] ids)
{ {
var factory = new ServerRegistrationFactory();
return Database.Fetch<ServerRegistrationDto>("WHERE id > 0") return Database.Fetch<ServerRegistrationDto>("WHERE id > 0")
.Select(x => factory.BuildEntity(x)); .Select(x => ServerRegistrationFactory.BuildEntity(x));
} }
protected override IEnumerable<IServerRegistration> PerformGetByQuery(IQuery<IServerRegistration> query) protected override IEnumerable<IServerRegistration> PerformGetByQuery(IQuery<IServerRegistration> query)
@@ -100,8 +99,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
{ {
((ServerRegistration)entity).AddingEntity(); ((ServerRegistration)entity).AddingEntity();
var factory = new ServerRegistrationFactory(); var dto = ServerRegistrationFactory.BuildDto(entity);
var dto = factory.BuildDto(entity);
var id = Convert.ToInt32(Database.Insert(dto)); var id = Convert.ToInt32(Database.Insert(dto));
entity.Id = id; entity.Id = id;
@@ -112,9 +110,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
protected override void PersistUpdatedItem(IServerRegistration entity) protected override void PersistUpdatedItem(IServerRegistration entity)
{ {
((ServerRegistration)entity).UpdatingEntity(); ((ServerRegistration)entity).UpdatingEntity();
var factory = new ServerRegistrationFactory(); var dto = ServerRegistrationFactory.BuildDto(entity);
var dto = factory.BuildDto(entity);
Database.Update(dto); Database.Update(dto);