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