using BeWo.Data.Access;
using BeWo.Data.Entities;

using BS.Shared.DataContracts;

namespace BeWo.Service.DCEntityMapper
{
    public class Wohnheimbuchung2Costbearer2SupportConceptRelDC_Wohnheimbuchung2Costbearer2SupportConcept : AbstractIDCEntityMapper<Wohnheimbuchung2Costbearer2SupportConcept, Wohnheimbuchung2Costbearer2SupportConceptRelationDC>
    {
        public override Wohnheimbuchung2Costbearer2SupportConceptRelationDC MergeWithDC(Wohnheimbuchung2Costbearer2SupportConcept pEntity, Wohnheimbuchung2Costbearer2SupportConceptRelationDC pDataContract)
        {
            pDataContract.Wohnheimbuchung2Costbearer2SupportConceptOid     = pEntity.Oid;
            pDataContract.Wohnheimbuchung2Costbearer2SupportConceptVersion = pEntity.Version;
            pDataContract.Notice                                           = pEntity.Notice;
            pDataContract.Costbearer2SupportConcept                        = MapperFactory.SupportConceptCostBearerRelDC_CostBearer2SupportConcept.MapToNewDC(pEntity.CostBearer2SupportConcept);
            pDataContract.StartDate                                        = pEntity.StartDate;
            pDataContract.EndDate                                          = pEntity.EndDate;

            return pDataContract;
        }

        public override Wohnheimbuchung2Costbearer2SupportConcept MergeWithEntity(Wohnheimbuchung2Costbearer2SupportConceptRelationDC pDataContract, Wohnheimbuchung2Costbearer2SupportConcept pEntity)
        {
            ConcurrencyCheck(pDataContract.Wohnheimbuchung2Costbearer2SupportConceptVersion, pEntity);

            pEntity.CostBearer2SupportConcept = null;

            if (pEntity.CostBearer2SupportConcept == null || pEntity.CostBearer2SupportConcept.Oid != pDataContract.Costbearer2SupportConcept.CostBearer2SupportConceptOid)
            {
                pEntity.CostBearer2SupportConcept = DAOFactory.GenericDAO.LoadByID<CostBearer2SupportConcept>(pDataContract.Costbearer2SupportConcept.CostBearer2SupportConceptOid.Value);
            }

            pEntity.StartDate = pDataContract.StartDate;
            pEntity.EndDate   = pDataContract.EndDate;
            pEntity.Notice    = pDataContract.Notice;

            return pEntity;
        }

        protected override bool AreDCAndEntityEqual(Wohnheimbuchung2Costbearer2SupportConceptRelationDC pDC, Wohnheimbuchung2Costbearer2SupportConcept pEntity)
        {
            if (pDC.Wohnheimbuchung2Costbearer2SupportConceptOid == null)
            {
                return false;
            }

            return pDC.Wohnheimbuchung2Costbearer2SupportConceptOid == pEntity.Oid;
        }
    }
}