示例#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());
            }
        }
示例#3
0
 public bool UpdateTechRole(string oldId, TechRoleDAO trdao)
 {
     try
     {
         if (!string.IsNullOrWhiteSpace(oldId) && trdao != null)
         {
             TechRole ns  = mapper.MapToEntity(trdao);
             TechRole old = ef.GetTechRoles().FirstOrDefault(a => a.TRName.Equals(oldId));
             ns.TechRoleID = old.TechRoleID;
             return(ef.UpdateTechRole(old, ns));
         }
         return(false);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
示例#4
0
 /// <summary>
 /// delete tech role
 /// </summary>
 /// <param name="trdao"></param>
 /// <returns></returns>
 public bool DeleteTechRole(TechRoleDAO trdao)
 {
     try
     {
         if (trdao != null)
         {
             TechRole tr       = mapper.MapToEntity(trdao);
             var      toDelete = ef.GetTechRoles().FirstOrDefault((m => m.TRName == tr.TRName));
             return(ef.DeleteTechRole(toDelete));
         }
         else
         {
             return(false);
         }
     }
     catch (Exception e)
     {
         throw;
     }
 }
示例#5
0
 /// <summary>
 /// insert tech role
 /// </summary>
 /// <param name="tr"></param>
 /// <returns>true if successful</returns>
 public bool InsertTechRole(TechRoleDAO tr)
 {
     try
     {
         if (tr != null)
         {
             //map it to EF object
             var itm = mapper.MapToEntity(tr);
             db.TechRole.Add(itm);
             return(db.SaveChanges() > 0);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception e)
     {
         throw;
     }
 }