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

using BS.Shared.DataContracts;

namespace BeWo.Service.DCEntityMapper
{
	public class Employee2SchedulerAppointmentDC_Employee2SchedulerAppointment : AbstractIDCEntityMapper<Employee2SchedulerAppointment, Employee2SchedulerAppointmentDC>
	{
		public override Employee2SchedulerAppointmentDC MergeWithDC(Employee2SchedulerAppointment pEntity, Employee2SchedulerAppointmentDC pDataContract)
		{
			pDataContract.Employee = MapperFactory.CompactEmployeeDC_Employee.MapToNewDC(pEntity.Employee);
			pDataContract.SchedulerAppointmentOid = pEntity.SchedulerAppointmentOid;
			pDataContract.ParticipationAnswer = pEntity.ParticipationAnswer;
			pDataContract.Employee2SchedulerAppointmentOid = pEntity.Oid;
			pDataContract.Employee2SchedulerAppointmentVersion = pEntity.Version;
			pDataContract.IsPChanged = pEntity.IsPChanged;
			pDataContract.IsPC_CheckedTs = pEntity.IsPC_CheckedTs;

			return pDataContract;
		}

		public override Employee2SchedulerAppointment MergeWithEntity(Employee2SchedulerAppointmentDC pDataContract, Employee2SchedulerAppointment pEntity)
		{
			ConcurrencyCheck(pDataContract.Employee2SchedulerAppointmentVersion, pEntity);

			if (pDataContract.Employee != null)
				pEntity.Employee = DAOFactory.GenericDAO.LoadByID<Employee>(pDataContract.Employee.EmployeeOid);

			pEntity.SchedulerAppointmentOid = pDataContract.SchedulerAppointmentOid;
			pEntity.ParticipationAnswer = pDataContract.ParticipationAnswer;
			pEntity.Oid = pDataContract.Employee2SchedulerAppointmentOid;
			pEntity.IsPChanged = pDataContract.IsPChanged;
			pEntity.IsPC_CheckedTs = pDataContract.IsPC_CheckedTs;

			return pEntity;
		}

		protected override bool AreDCAndEntityEqual(Employee2SchedulerAppointmentDC pDC, Employee2SchedulerAppointment pEntity)
		{
			if (pDC.Employee2SchedulerAppointmentOid == null) return false;
			
			return pDC.Employee2SchedulerAppointmentOid == pEntity.Oid;
		}
	}
}
