/// <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()); } }
/// <summary> /// update status /// </summary> /// <param name="oldId"></param> /// <param name="sdao"></param> /// <returns></returns> public bool UpdateStatus(string oldId, ShiftStatusDAO sdao) { try { if (!string.IsNullOrWhiteSpace(oldId) && sdao != null) { ShiftStatus ns = mapper.MapToEntity(sdao); ShiftStatus old = ef.GetStatuss().FirstOrDefault(a => a.SSDescription.Equals(oldId)); ns.ShiftStatusID = old.ShiftStatusID; return(ef.UpdateStatus(old, ns)); } return(false); } catch (Exception e) { return(false); } }
/// <summary> /// delete status /// </summary> /// <param name="ssdao"></param> /// <returns></returns> public bool DeleteShiftStatus(ShiftStatusDAO ssdao) { try { if (ssdao != null) { ShiftStatus ss = mapper.MapToEntity(ssdao); var toDelete = ef.GetStatuss().FirstOrDefault((m => m.SSDescription == ss.SSDescription)); return(ef.DeleteStatus(toDelete)); } else { return(false); } } catch (Exception e) { throw; } }
/// <summary> /// Insert Shift Status /// </summary> /// <param name="ss"></param> /// <returns>true if successful</returns> public bool InsertShiftStatus(ShiftStatusDAO ss) { try { if (ss != null) { //map it to EF object var itm = mapper.MapToEntity(ss); db.ShiftStatus.Add(itm); return(db.SaveChanges() > 0); } else { return(false); } } catch (Exception e) { throw; } }