115 lines
4.4 KiB
C#
115 lines
4.4 KiB
C#
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
|
|
using BS.Shared.DataContracts;
|
|
using System.Collections.Generic;
|
|
|
|
namespace BeWo.Service.DCEntityMapper
|
|
{
|
|
public class AiPromptbausteinDC_AiPromptbaustein : AbstractIDCEntityMapper<AiPromptbaustein, AiPromptbausteinDC>
|
|
{
|
|
public IList<AiPromptbausteinDC> CreateDcList(IEnumerable<AiPromptbaustein> aiPromptbausteine)
|
|
{
|
|
var list = new List<AiPromptbausteinDC>();
|
|
Dictionary<long, IList<long>> parentChildDict = new Dictionary<long, IList<long>>();
|
|
foreach (var aiPromptbaustein in aiPromptbausteine)
|
|
{
|
|
var dc = CreateAiPromptbausteinDC(aiPromptbaustein, parentChildDict);
|
|
list.Add(dc);
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
private AiPromptbausteinDC CreateAiPromptbausteinDC(AiPromptbaustein tm, Dictionary<long, IList<long>> parentChildDict)
|
|
{
|
|
var dc = new AiPromptbausteinDC();
|
|
dc.Position = tm.Position;
|
|
dc.Version = tm.Version.Value;
|
|
dc.Oid = tm.Oid.Value;
|
|
dc.Text = tm.Text;
|
|
dc.Name = tm.Name;
|
|
dc.IsOnlyForEmployee = tm.IsOnlyForEmployee;
|
|
dc.IsParent = tm.IsParent;
|
|
dc.IsExpanded = tm.IsExpanded;
|
|
dc.ActivationType = tm.IsActive;
|
|
|
|
dc.Employee = tm.Employee != null ? MapperFactory.CompactEmployeeDC_Employee.MapToNewDC(tm.Employee) : null;
|
|
|
|
if (tm.Parent != null)
|
|
{
|
|
// Endlosschleifen vermeiden: Parent eines Bausteins darf nicht gleichzeitig Kind des gleichen Bausteins sein
|
|
if (!parentChildDict.ContainsKey(tm.Parent.Oid.Value))
|
|
{
|
|
parentChildDict.Add(tm.Parent.Oid.Value, new List<long>());
|
|
}
|
|
parentChildDict[tm.Parent.Oid.Value].Add(tm.Oid.Value);
|
|
|
|
bool addParent = true;
|
|
if (parentChildDict.ContainsKey(tm.Oid.Value))
|
|
{
|
|
var childOids = parentChildDict[tm.Oid.Value];
|
|
|
|
if (childOids.Contains(tm.Parent.Oid.Value))
|
|
{
|
|
addParent = false;
|
|
}
|
|
}
|
|
|
|
if (addParent && tm.Parent.IsActive != BS.Shared.ActivationTypeId.Deleted)
|
|
{
|
|
dc.Parent = CreateAiPromptbausteinDC(tm.Parent, parentChildDict);
|
|
}
|
|
}
|
|
|
|
return dc;
|
|
}
|
|
|
|
public override AiPromptbausteinDC MergeWithDC(AiPromptbaustein entity, AiPromptbausteinDC dataContract)
|
|
{
|
|
dataContract.Position = entity.Position;
|
|
dataContract.Version = entity.Version.Value;
|
|
dataContract.Oid = entity.Oid.Value;
|
|
dataContract.Text = entity.Text;
|
|
dataContract.Name = entity.Name;
|
|
dataContract.IsOnlyForEmployee = entity.IsOnlyForEmployee;
|
|
dataContract.ActivationType = entity.IsActive;
|
|
dataContract.IsParent = entity.IsParent;
|
|
|
|
if (entity.Employee != null)
|
|
dataContract.Employee = MapperFactory.CompactEmployeeDC_Employee.MapToNewDC(entity.Employee);
|
|
|
|
if (entity.Parent != null)
|
|
dataContract.Parent = MapperFactory.AiPromptbausteinDC_AiPromptbaustein.MapToNewDC(entity.Parent);
|
|
|
|
return dataContract;
|
|
}
|
|
|
|
public override AiPromptbaustein MergeWithEntity(AiPromptbausteinDC dataContract, AiPromptbaustein entity)
|
|
{
|
|
ConcurrencyCheck(dataContract.Version, entity);
|
|
|
|
entity.Position = dataContract.Position;
|
|
entity.Oid = dataContract.Oid;
|
|
entity.Text = dataContract.Text;
|
|
entity.Name = dataContract.Name;
|
|
entity.IsOnlyForEmployee = dataContract.IsOnlyForEmployee;
|
|
entity.IsActive = dataContract.ActivationType;
|
|
entity.IsParent = dataContract.IsParent;
|
|
|
|
if (dataContract.Employee != null)
|
|
entity.Employee = DAOFactory.GenericDAO.LoadByID<Employee>(dataContract.Employee.EmployeeOid);
|
|
|
|
if (dataContract.Parent != null)
|
|
entity.Parent = DAOFactory.GenericDAO.LoadByID<AiPromptbaustein>(dataContract.Parent.Oid.Value);
|
|
|
|
return entity;
|
|
}
|
|
|
|
protected override bool AreDCAndEntityEqual(AiPromptbausteinDC dc, AiPromptbaustein entity)
|
|
{
|
|
return dc.Oid == entity.Oid;
|
|
}
|
|
}
|
|
}
|