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 RelationService [Serializable] public class RelationService : ServiceTemplate, IRelationService { #region Private functions and declaration Cache _cache = new Cache(typeof(Relation)); #endregion #region constructor public RelationService() { } #endregion #region Object private void MapObject(Relation oRelation, DataReader oReader) { base.SetObjectID(oRelation, oReader.GetID("RELATIONID")); oRelation.Code = oReader.GetString("CODE"); oRelation.Description = oReader.GetString("DESCRIPTION"); oRelation.Sequence = oReader.GetInt32("SequenceNo").Value; oRelation.Status = (EnumStatus)oReader.GetInt32("Status").Value; oRelation.CreatedBy = oReader.GetID("CreatedBy"); oRelation.CreatedDate = oReader.GetDateTime("CreationDate").Value; oRelation.ModifiedBy = oReader.GetID("ModifiedBy"); oRelation.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oRelation, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Relation oRelation = new Relation(); MapObject(oRelation, oReader); return oRelation as T; } protected Relation CreateObject(DataReader oReader) { Relation oRelation = new Relation(); MapObject(oRelation, oReader); return oRelation; } #endregion #region Service implementation public Relation Get(ID id) { Relation oRelation = new Relation(); #region Cache Header oRelation = _cache["Get", id] as Relation; if (oRelation != null) return oRelation; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(RelationDA.Get(tc, id)); if (oreader.Read()) { oRelation = 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(oRelation, "Get", id); #endregion return oRelation; } public Relation Get(string sCode) { Relation oRelation = new Relation(); #region Cache Header oRelation = _cache["Get", sCode] as Relation; if (oRelation != null) return oRelation; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(RelationDA.Get(tc, sCode)); if (oreader.Read()) { oRelation = 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(oRelation, "Get", sCode); #endregion return oRelation; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate relations = _cache["Get"] as ObjectsTemplate; if (relations != null) return relations; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(RelationDA.Get(tc)); relations = 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(relations, "Get"); #endregion return relations; } public ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate relations = _cache["Get"] as ObjectsTemplate; if (relations != null) return relations; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(RelationDA.Get(tc, status)); relations = 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(relations, "Get", status); #endregion return relations; } public ID Save(Relation oRelation) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oRelation.IsNew) { int id = tc.GenerateID("PERSONRELATION", "RELATIONID"); base.SetObjectID(oRelation, ID.FromInteger(id)); RelationDA.Insert(tc, oRelation); } else { RelationDA.Update(tc, oRelation); } tc.End(); return oRelation.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); RelationDA.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 }