Files
BeWoPlaner/Service/DCEntityMapper/CustomerEmployeeRelDC_Employee2CustomerMapper.cs

65 lines
2.7 KiB
C#

using BeWo.Data.Access;
using BeWo.Data.Entities;
using BS.Shared;
using BS.Shared.DataContracts;
namespace BeWo.Service.DCEntityMapper
{
public class CustomerEmployeeRelDC_Employee2CustomerMapper : AbstractIDCEntityMapper<Employee2Customer, CustomerEmployeeRelationDC>
{
public override CustomerEmployeeRelationDC MergeWithDC(Employee2Customer pEntity, CustomerEmployeeRelationDC pDataContract)
{
if (pEntity.ValueList.Count > 0)
{
pDataContract.RelationRole = MapperFactory.ValueListEntryDC_ValueListEntry.MapToNewDC(pEntity.ValueList[0].Entry);
}
pDataContract.Employee = MapperFactory.CompactEmployeeDC_Employee.MapToNewDC(pEntity.Employee);
pDataContract.Customer = MapperFactory.CompactCustomerDC_Customer.MapToNewDC(pEntity.Customer);
pDataContract.Employee2CustomerOid = pEntity.Oid;
pDataContract.Employee2CustomerVersion = pEntity.Version;
pDataContract.Notice = pEntity.Notice;
pDataContract.Chatpartner = pEntity.Chatpartner;
pDataContract.StartDate = pEntity.StartDate;
pDataContract.EndDate = pEntity.EndDate;
return pDataContract;
}
public override Employee2Customer MergeWithEntity(CustomerEmployeeRelationDC pDataContract, Employee2Customer pEntity)
{
this.ConcurrencyCheck(pDataContract.Employee2CustomerVersion, pEntity);
MapperFactory.ValueListEntryDC_ValueListEntry.MapUniqueTypeValueListEntryBack2Entity(pDataContract.RelationRole, pEntity.ValueList, ValueListEntryType.StaffRoleType, TableID.Employee2Customer);
if (pDataContract.Employee != null)
{
pEntity.Employee = DAOFactory.GenericDAO.LoadByID<Employee>(pDataContract.Employee.EmployeeOid);
}
if (pDataContract.Customer != null)
{
pEntity.Customer = DAOFactory.GenericDAO.LoadByID<Customer>(pDataContract.Customer.CustomerOid);
}
pEntity.Oid = pDataContract.Employee2CustomerOid;
pEntity.Notice = pDataContract.Notice;
pEntity.Chatpartner = pDataContract.Chatpartner;
pEntity.StartDate = pDataContract.StartDate;
pEntity.EndDate = pDataContract.EndDate;
return pEntity;
}
protected override bool AreDCAndEntityEqual(CustomerEmployeeRelationDC pDC, Employee2Customer pEntity)
{
if (pDC.Employee2CustomerOid == null)
{
return false;
}
return pDC.Employee2CustomerOid == pEntity.Oid;
}
}
}