/// <summary> /// map the dao to the entity /// </summary> /// <param name="ssdao"></param> /// <returns></returns> public Tech MapToEntity(TechDAO tdao) { Tech t = null; Tech fromDB = null; //use automapper to map matching properties var mapper = TechMapper.CreateMapper(); if (tdao != null) { t = mapper.Map <Tech>(tdao); //get original object from db if (!string.IsNullOrWhiteSpace(tdao.Name)) { fromDB = db.Tech.Where(m => m.Email.Equals(tdao.Email)).FirstOrDefault(); } //if db object exist then use existing object and map properties sent from dao if (fromDB != null) { t = fromDB; if (!string.IsNullOrWhiteSpace(tdao.Email)) { t.Email = tdao.Email; } } //if db object does not exist use automapper version of object and set active to true else { t.IsActive = true; } } return(t); }
/// <summary> /// map the entity to the dao /// </summary> /// <param name="s"></param> /// <returns></returns> public TechDAO MapToDao(Tech t) { var mapper = TechMapper.CreateMapper(); if (t != null) { TechDAO tdao = mapper.Map <TechDAO>(t); return(tdao); } else { return(new TechDAO()); } }