using BS.Shared.DataContracts;
using BeWo.Data.Access;
using BeWo.Data.Entities;

namespace BeWo.Service.DCEntityMapper
{
    public class AdditionalServiceRegionDC_AdditionalServiceRegion : AbstractIDCEntityMapper<AdditionalServiceRegion, AdditionalServiceRegionDC>
    {
        public override AdditionalServiceRegionDC MergeWithDC(AdditionalServiceRegion pEntity, AdditionalServiceRegionDC pDataContract)
        {
            pDataContract.AdditionalServiceRegionOid = pEntity.Oid;
            pDataContract.AdditionalServiceRegionVersion = pEntity.Version;
            pDataContract.InsertedOn = pEntity.InsTs;
            pDataContract.InsUser = pEntity.InsUser;
            pDataContract.Notice = pEntity.Notice;
            pDataContract.AdditionalServiceOid = pEntity.AdditionalServiceOid;
            pDataContract.Name = pEntity.Name;

            if (pEntity.AdditionalService != null)
                pDataContract.AdditionalService = MapperFactory.AdditionalServiceDC_AdditionalService.MapToNewDC(pEntity.AdditionalService);

            return pDataContract;
        }

        public override AdditionalServiceRegion MergeWithEntity(AdditionalServiceRegionDC pDataContract, AdditionalServiceRegion pEntity)
        {
            ConcurrencyCheck(pDataContract.AdditionalServiceRegionVersion, pEntity);

            pEntity.Oid = pDataContract.AdditionalServiceRegionOid;
            pEntity.Name = pDataContract.Name;
            pEntity.AdditionalServiceOid = pDataContract.AdditionalServiceOid;
            pEntity.Notice = pDataContract.Notice;

            if (pEntity.AdditionalService == null || pEntity.AdditionalService.Oid != pDataContract.AdditionalService.AdditionalServiceOid)
                pEntity.AdditionalService = DAOFactory.GenericDAO.LoadByID<AdditionalService>(pDataContract.AdditionalService.AdditionalServiceOid.Value);

            return pEntity;
        }

        protected override bool AreDCAndEntityEqual(AdditionalServiceRegionDC pDC, AdditionalServiceRegion pEntity)
        {
            if (pDC.AdditionalServiceRegionOid == null)
                return false;
            return pDC.AdditionalServiceRegionOid == pEntity.Oid;
        }
    }
}
