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

using BS.Shared.DataContracts;

namespace BeWo.Service.DCEntityMapper
{
    public class NewsItemDC_NewsItem : AbstractIDCEntityMapper<NewsItem, NewsItemDC>
    {
        public override NewsItemDC MergeWithDC(NewsItem pEntity, NewsItemDC pDataContract)
        {
            pDataContract.NewsItemOid = pEntity.Oid;
            pDataContract.NewsItemVersion = pEntity.Version;
            pDataContract.PublishDate = pEntity.PublishDate;
            pDataContract.Text = pEntity.Text;
            pDataContract.Title = pEntity.Title;
			if (pEntity.Team != null)
				pDataContract.Team = MapperFactory.CompactTeamDC_Team.MapToNewDC(pEntity.Team);
            return pDataContract;
        }

        public override NewsItem MergeWithEntity(NewsItemDC pDataContract, NewsItem pEntity)
        {
            this.ConcurrencyCheck(pDataContract.NewsItemVersion, pEntity);
            pEntity.Oid = pDataContract.NewsItemOid;
            pEntity.PublishDate = pDataContract.PublishDate;
            pEntity.Text = pDataContract.Text;
            pEntity.Title = pDataContract.Title;
			if (pDataContract.Team != null)
				pEntity.Team = DAOFactory.GenericDAO.LoadByID<Team>(pDataContract.Team.TeamOid);
            return pEntity;
        }

        protected override bool AreDCAndEntityEqual(NewsItemDC pDC, NewsItem pEntity)
        {
            if (pDC.NewsItemOid == null)
            {
                return false;
            }

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