using System; using Ease.Core.Model; using Ease.Core.DataAccess; using HRM.BO; using System.Collections.Generic; using Ease.Core.Utility; namespace HRM.DA { #region Nationality Service public class NationalityService : ServiceTemplate, INationalityService { #region constructor public NationalityService() { } #endregion #region Object private void MapObject(Nationality oNationality, DataReader oReader) { base.SetObjectID(oNationality, oReader.GetInt32("NATIONALITYID").Value); 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.GetInt32("CreatedBy", 0); oNationality.CreatedDate = oReader.GetDateTime("CreationDate").Value; oNationality.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oNationality.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oNationality, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Nationality oNationality = new Nationality(); MapObject(oNationality, oReader); return oNationality as T; } #endregion #region Service implementation public Nationality Get(int id) { Nationality oNationality = null; 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 } return oNationality; } public Nationality Get(TransactionContext tc, int id) { Nationality oNationality = null; try { DataReader oreader = new DataReader(NationalityDA.Get(tc, id)); if (oreader.Read()) { oNationality = this.CreateObject(oreader); } oreader.Close(); } catch (Exception e) { #region Handle Exception ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oNationality; } public Nationality Get(string sCode) { Nationality oNationality = null; 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 } return oNationality; } public List Get() { List nationalities = new List(); 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 } return nationalities; } public List Get(EnumStatus status) { List nationalities = new List(); 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 } return nationalities; } public int 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); oNationality.Sequence = seqID; if (oNationality.Code == "") oNationality.Code = GlobalFunctionService.GetMaxCode(tc, "", "", "NATIONALITY", "NATIONALITYID"); 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(int 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 }