CB bugfixing
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using BeWo.Data.Access;
|
||||
using System.Collections.Generic;
|
||||
using BeWo.Data.Access;
|
||||
using BeWo.Data.Entities;
|
||||
|
||||
using BS.Shared.DataContracts;
|
||||
@@ -7,6 +8,69 @@ namespace BeWo.Service.DCEntityMapper
|
||||
{
|
||||
public class TextModuleDC_TextModule : AbstractIDCEntityMapper<TextModule, TextModuleDC>
|
||||
{
|
||||
public IList<TextModuleDC> CreateDcList(IEnumerable<TextModule> textmodules)
|
||||
{
|
||||
var list = new List<TextModuleDC>();
|
||||
Dictionary<long, IList<long>> parentChildDict = new Dictionary<long, IList<long>>();
|
||||
foreach (var tm in textmodules)
|
||||
{
|
||||
var dc = CreateTextModuleDC(tm, parentChildDict);
|
||||
|
||||
list.Add(dc);
|
||||
}
|
||||
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
private TextModuleDC CreateTextModuleDC(TextModule tm, Dictionary<long, IList<long>> parentChildDict)
|
||||
{
|
||||
var dc = new TextModuleDC();
|
||||
dc.Position = tm.Position;
|
||||
dc.TextModuleVersion = tm.Version.Value;
|
||||
dc.TextModuleOid = 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.ServiceCategory = tm.ServiceCategory != null ? MapperFactory.ServiceCategoryDC_ServiceCategory.MapToNewDC(tm.ServiceCategory) : null;
|
||||
|
||||
dc.Employee = tm.Employee != null ? MapperFactory.CompactEmployeeDC_Employee.MapToNewDC(tm.Employee) : null;
|
||||
|
||||
|
||||
|
||||
if (tm.Parent != null)
|
||||
{
|
||||
//Vermeide Endlosschleifen. Es gab mal den Fall, da hat es ein Kunde geschafft, dass der Parent eines Textbausteins gleichzeitig ein Kind desselben Bausteins war.
|
||||
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)
|
||||
{
|
||||
dc.Parent = CreateTextModuleDC(tm.Parent, parentChildDict);
|
||||
}
|
||||
}
|
||||
|
||||
return dc;
|
||||
}
|
||||
|
||||
public override TextModuleDC MergeWithDC(TextModule pEntity, TextModuleDC pDataContract)
|
||||
{
|
||||
pDataContract.Position = pEntity.Position;
|
||||
|
||||
Reference in New Issue
Block a user