113 lines
4.4 KiB
C#
113 lines
4.4 KiB
C#
using System.Collections.Generic;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts;
|
|
|
|
namespace BeWo.Service.DCEntityMapper
|
|
{
|
|
public class CustomerPersonRelationDC_Customer2Person : AbstractIDCEntityMapper<Customer2Person, CustomerPersonRelationDC>
|
|
{
|
|
public override CustomerPersonRelationDC MergeWithDC(Customer2Person pEntity, CustomerPersonRelationDC pDataContract)
|
|
{
|
|
if (pEntity.ValueList.Count > 0)
|
|
{
|
|
pDataContract.RelationRole = MapperFactory.ValueListEntryDC_ValueListEntry.MapToNewDC(pEntity.ValueList[0].Entry);
|
|
}
|
|
|
|
|
|
pDataContract.Customer2PersonNotice = pEntity.Notice;
|
|
pDataContract.Customer2PersonOid = pEntity.Oid;
|
|
pDataContract.Customer2PersonVersion = pEntity.Version;
|
|
pDataContract.Person = MapperFactory.CompactPersonDC_Person.MapToNewDC(pEntity.Person);
|
|
|
|
pDataContract.IstFamilie = pEntity.IstFamilie;
|
|
|
|
|
|
if(pEntity.Organisation != null)
|
|
pDataContract.Organisation = MapperFactory.CompactOrganisationDC_Organisation.MapToNewDC(pEntity.Organisation);
|
|
|
|
if (pDataContract.Person != null && pEntity.Person.Contacts != null)
|
|
{
|
|
foreach (var contact in pEntity.Person.Contacts)
|
|
{
|
|
|
|
if (contact.Type == ContactType.private_Mail)
|
|
{
|
|
pDataContract.Person.Communication3 = contact.Value;
|
|
}
|
|
|
|
if (contact.Type == ContactType.private_Fax)
|
|
{
|
|
pDataContract.Person.Communication4 = contact.Value;
|
|
}
|
|
|
|
if (contact.Type == ContactType.private_Phone)
|
|
{
|
|
pDataContract.Person.Communication1 = contact.Value;
|
|
}
|
|
|
|
if (contact.Type == ContactType.private_MobilePhone)
|
|
{
|
|
pDataContract.Person.Communication2 = contact.Value;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return pDataContract;
|
|
}
|
|
|
|
public override Customer2Person MergeWithEntity(CustomerPersonRelationDC pDataContract, Customer2Person pEntity)
|
|
{
|
|
var type = ValueListEntryType.EnvironmentPersonType;
|
|
|
|
if (pDataContract != null && pDataContract.RelationRole != null)
|
|
{
|
|
type = pDataContract.RelationRole.Type;
|
|
}
|
|
MapperFactory.ValueListEntryDC_ValueListEntry.MapUniqueTypeValueListEntryBack2Entity(pDataContract.RelationRole, pEntity.ValueList, type, TableID.Customer2Person);
|
|
|
|
pEntity.Oid = pDataContract.Customer2PersonOid;
|
|
pEntity.Version = pDataContract.Customer2PersonVersion;
|
|
pEntity.Notice = pDataContract.Customer2PersonNotice;
|
|
pEntity.IstFamilie = pDataContract.IstFamilie;
|
|
pEntity.Person = DAOFactory.GenericDAO.LoadByID<Person>(pDataContract.Person.PersonOid);
|
|
|
|
if (pDataContract.Organisation != null)
|
|
{
|
|
pEntity.Organisation = DAOFactory.GenericDAO.LoadByID<Organisation>(pDataContract.Organisation.OrganisationOid);
|
|
}
|
|
|
|
return pEntity;
|
|
}
|
|
|
|
protected override bool AreDCAndEntityEqual(CustomerPersonRelationDC pDC, Customer2Person pEntity)
|
|
{
|
|
if (pDC.Customer2PersonOid == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return pDC.Customer2PersonOid == pEntity.Oid;
|
|
}
|
|
|
|
public List<CustomerPersonRelationDC> MapToNewDCsWithCustomer(IList<Customer2Person> relList)
|
|
{
|
|
List<CustomerPersonRelationDC> lResult = new List<CustomerPersonRelationDC>();
|
|
if (relList != null)
|
|
{
|
|
foreach (var iEntity in relList)
|
|
{
|
|
var dc = this.MergeWithDC(iEntity, CreateNewDC());
|
|
var c = DAOFactory.GenericDAO.LoadByID<Customer>(iEntity.CustomerOid);
|
|
|
|
dc.Customer = MapperFactory.CompactCustomerDC_Customer.MapToNewDC(c);
|
|
lResult.Add(dc);
|
|
}
|
|
}
|
|
return lResult;
|
|
}
|
|
}
|
|
} |