using System; using Ease.Core.Model; using Ease.Core.DataAccess; using HRM.BO; using System.Collections.Generic; using Ease.Core.Utility; namespace HRM.DA { public class HobbyService : ServiceTemplate, IHobbyService { #region constructor public HobbyService() { } #endregion #region Object private void MapObject(Hobby oHobby, DataReader oReader) { base.SetObjectID(oHobby, oReader.GetInt32("HOBBYID").Value); oHobby.Code = oReader.GetString("CODE"); oHobby.Description = oReader.GetString("DESCRIPTION"); oHobby.Sequence = oReader.GetInt32("SequenceNo").Value; oHobby.Status = (EnumStatus)oReader.GetInt32("Status").Value; oHobby.CreatedBy = oReader.GetInt32("CreatedBy", 0); oHobby.CreatedDate = oReader.GetDateTime("CreationDate").Value; oHobby.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oHobby.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oHobby, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Hobby oHobby = new Hobby(); MapObject(oHobby, oReader); return oHobby as T; } #endregion #region Service implementation public Hobby Get(int id) { Hobby oHobby = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(HobbyDA.Get(tc, id)); if (oreader.Read()) { oHobby = this.CreateObject(oreader); } oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oHobby; } public Hobby Get(string sCode) { Hobby oHobby = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(HobbyDA.Get(tc, sCode)); if (oreader.Read()) { oHobby = this.CreateObject(oreader); } oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oHobby; } public List Get() { List hobbies = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(HobbyDA.Get(tc)); hobbies = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return hobbies; } public List Get(EnumStatus status) { List hobbies = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(HobbyDA.Get(tc, status)); hobbies = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return hobbies; } public int Save(Hobby oHobby) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oHobby.IsNew) { int id = tc.GenerateID("HOBBY", "HOBBYID"); base.SetObjectID(oHobby, id); HobbyDA.Insert(tc, oHobby); } else { HobbyDA.Update(tc, oHobby); } tc.End(); return oHobby.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); HobbyDA.Delete(tc, id); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion } }