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