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 InstitutionService [Serializable] public class InstitutionService : ServiceTemplate, IInstitutionService { #region Private functions and declaration Cache _cache = new Cache(typeof(Institution)); #endregion #region constructor public InstitutionService() { } #endregion #region Object private void MapObject(Institution oInstitution, DataReader oReader) { base.SetObjectID(oInstitution, oReader.GetID("INSTITUTIONID")); oInstitution.Code = oReader.GetString("CODE"); oInstitution.Name = oReader.GetString("NAME"); oInstitution.Type = oReader.GetInt32("TYPE").Value; oInstitution.EducationTypeID = oReader.GetID("EducationTypeID"); oInstitution.Sequence = oReader.GetInt32("SequenceNo").Value; oInstitution.Status = (EnumStatus)oReader.GetInt32("Status").Value; oInstitution.CreatedBy = oReader.GetID("CreatedBy"); oInstitution.CreatedDate = oReader.GetDateTime("CreationDate").Value; oInstitution.ModifiedBy = oReader.GetID("ModifiedBy"); oInstitution.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oInstitution, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Institution oInstitution = new Institution(); MapObject(oInstitution, oReader); return oInstitution as T; } protected Institution CreateObject(DataReader oReader) { Institution oInstitution = new Institution(); MapObject(oInstitution, oReader); return oInstitution; } #endregion #region Service implementation public Institution Get(ID id) { Institution oInstitution = new Institution(); #region Cache Header oInstitution = _cache["Get", id] as Institution; if (oInstitution != null) return oInstitution; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(InstitutionDA.Get(tc, id)); if (oreader.Read()) { oInstitution = 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(oInstitution, "Get", id); #endregion return oInstitution; } public Institution Get(string sCode) { Institution oInstitution = new Institution(); #region Cache Header oInstitution = _cache["Get", sCode] as Institution; if (oInstitution != null) return oInstitution; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(InstitutionDA.Get(tc, sCode)); if (oreader.Read()) { oInstitution = 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(oInstitution, "Get", sCode); #endregion return oInstitution; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate institutions = _cache["Get"] as ObjectsTemplate; if (institutions != null) return institutions; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(InstitutionDA.Get(tc)); institutions = 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(institutions, "Get"); #endregion return institutions; } public ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate institutions = _cache["Get"] as ObjectsTemplate; if (institutions != null) return institutions; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(InstitutionDA.Get(tc, status)); institutions = 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(institutions, "Get", status); #endregion return institutions; } public ObjectsTemplate GetByInstituteType(EnmInstituteType type) { #region Cache Header ObjectsTemplate institutions = _cache["GetByInstituteType"] as ObjectsTemplate; if (institutions != null) return institutions; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(InstitutionDA.GetByInstituteType(tc, type)); institutions = 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(institutions, "GetByInstituteType", type); #endregion return institutions; } public ID Save(Institution oInstitution) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oInstitution.IsNew) { int id = tc.GenerateID("INSTITUTION", "INSTITUTIONID"); base.SetObjectID(oInstitution, ID.FromInteger(id)); InstitutionDA.Insert(tc, oInstitution); } else { InstitutionDA.Update(tc, oInstitution); } tc.End(); return oInstitution.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); InstitutionDA.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 } } public bool IsExists(string Code) { TransactionContext tc = null; bool isExists = false; try { tc = TransactionContext.Begin(true); isExists = InstitutionDA.IsExists(tc, Code); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to get Skill due to " + e.Message, e); #endregion } return isExists; } #endregion } #endregion }