using BeWo.Data.Entities;

using BS.Shared.DataContracts;

namespace BeWo.Service.DCEntityMapper
{
    public class LoginDC_Login : AbstractIDCEntityMapper<Login, LoginDC>
    {
        public override LoginDC MergeWithDC(Login pEntity, LoginDC pDataContract)
        {
            pDataContract.LoginOid = pEntity.Oid;
            pDataContract.LoginVersion = pEntity.Version;
            pDataContract.Browser = pEntity.Browser;
            pDataContract.HostName = pEntity.HostName;
            pDataContract.IPAddress = pEntity.IPAddress;
            pDataContract.LoginDate = pEntity.LoginDate;
            pDataContract.LoginName = pEntity.LoginName;
            pDataContract.Password = pEntity.Password;
            pDataContract.Referrer = pEntity.Referrer;

            return pDataContract;
        }

        public override Login MergeWithEntity(LoginDC pDataContract, Login pEntity)
        {
            this.ConcurrencyCheck(pDataContract.LoginVersion, pEntity);

            pEntity.Oid = pDataContract.LoginOid;
            pEntity.Browser = pDataContract.Browser;
            pEntity.HostName = pDataContract.HostName;
            pEntity.IPAddress = pDataContract.IPAddress;
            pEntity.LoginDate = pDataContract.LoginDate;
            pEntity.LoginName = pDataContract.LoginName;
            pEntity.Password = pDataContract.Password;
            pEntity.Referrer = pDataContract.Referrer;

            return pEntity;
        }

        protected override bool AreDCAndEntityEqual(LoginDC pDC, Login pEntity)
        {
            if (pDC.LoginOid == null)
            {
                return false;
            }

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