using System; using System.Data; using System.Linq; using Ease.CoreV35; using Ease.CoreV35.Model; using Ease.CoreV35.DataAccess; using System.Collections.Generic; using Payroll.BO; using Ease.CoreV35.Caching; namespace Payroll.Service { #region class HobbyService [Serializable] public class HobbyService : ServiceTemplate, IHobbyService { #region Private functions and declaration Cache _cache = new Cache(typeof(Hobby)); #endregion #region constructor public HobbyService() { } #endregion #region Object private void MapObject(Hobby oHobby, DataReader oReader) { base.SetObjectID(oHobby, oReader.GetID("HOBBYID")); 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.GetID("CreatedBy"); oHobby.CreatedDate = oReader.GetDateTime("CreationDate").Value; oHobby.ModifiedBy = oReader.GetID("ModifiedBy"); oHobby.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oHobby, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Hobby oHobby = new Hobby(); MapObject(oHobby, oReader); return oHobby as T; } protected Hobby CreateObject(DataReader oReader) { Hobby oHobby = new Hobby(); MapObject(oHobby, oReader); return oHobby; } #endregion #region Service implementation public Hobby Get(ID id) { Hobby oHobby = new Hobby(); #region Cache Header oHobby = _cache["Get", id] as Hobby; if (oHobby != null) return oHobby; #endregion 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 } #region Cache Footer _cache.Add(oHobby, "Get", id); #endregion return oHobby; } public Hobby Get(string sCode) { Hobby oHobby = new Hobby(); #region Cache Header oHobby = _cache["Get", sCode] as Hobby; if (oHobby != null) return oHobby; #endregion 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 } #region Cache Footer _cache.Add(oHobby, "Get", sCode); #endregion return oHobby; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate hobbies = _cache["Get"] as ObjectsTemplate; if (hobbies != null) return hobbies; #endregion 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 } #region Cache Footer _cache.Add(hobbies, "Get"); #endregion return hobbies; } public ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate hobbies = _cache["Get"] as ObjectsTemplate; if (hobbies != null) return hobbies; #endregion 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 } #region Cache Footer _cache.Add(hobbies, "Get", status); #endregion return hobbies; } public ID Save(Hobby oHobby) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oHobby.IsNew) { int id = tc.GenerateID("HOBBY", "HOBBYID"); base.SetObjectID(oHobby, ID.FromInteger(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(ID 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 } #endregion }