예제 #1
0
        /// <summary>
        ///  map the dao to the entity
        /// </summary>
        /// <param name="ssdao"></param>
        /// <returns></returns>
        public TechRole MapToEntity(TechRoleDAO trdao)
        {
            TechRole tr     = null;
            TechRole fromDB = null;
            //use automapper to map matching properties
            var mapper = TechRoleMapper.CreateMapper();

            if (trdao != null)
            {
                tr = mapper.Map <TechRole>(trdao);

                //get original object from db
                if (!string.IsNullOrWhiteSpace(trdao.TRName))
                {
                    fromDB = db.TechRole.Where(m => m.TRName.Equals(trdao.TRName)).FirstOrDefault();
                }
                //if db object exist then use existing object and map properties sent from dao
                if (fromDB != null)
                {
                    tr = fromDB;
                    if (!string.IsNullOrWhiteSpace(trdao.TRName))
                    {
                        tr.TRName = trdao.TRName;
                    }
                }
                //if db object does not exist use automapper version of object and set active to true
                else
                {
                    tr.IsActive = true;
                }
            }
            return(tr);
        }
예제 #2
0
        /// <summary>
        /// map the entity to the dao
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public TechRoleDAO MapToDao(TechRole tr)
        {
            var mapper = TechRoleMapper.CreateMapper();

            if (tr != null)
            {
                TechRoleDAO trdao = mapper.Map <TechRoleDAO>(tr);
                return(trdao);
            }
            else
            {
                return(new TechRoleDAO());
            }
        }