using System; using Ease.Core.Model; using Ease.Core.DataAccess; using HRM.BO; using System.Collections.Generic; using Ease.Core.Utility; namespace HRM.DA { public class AllergyService : ServiceTemplate, IAllergyService { #region constructor public AllergyService() { } #endregion #region Object private void MapObject(Allergy oAllergy, DataReader oReader) { base.SetObjectID(oAllergy, oReader.GetInt32("ALLERGYID").Value); oAllergy.Code = oReader.GetString("CODE"); oAllergy.Description = oReader.GetString("DESCRIPTION"); oAllergy.Sequence = oReader.GetInt32("SequenceNo").Value; oAllergy.Status = (EnumStatus)oReader.GetInt32("Status").Value; oAllergy.CreatedBy = oReader.GetInt32("CreatedBy", 0); oAllergy.CreatedDate = oReader.GetDateTime("CreationDate").Value; oAllergy.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oAllergy.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oAllergy, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Allergy oAllergy = new Allergy(); MapObject(oAllergy, oReader); return oAllergy as T; } #endregion #region Service implementation public Allergy Get(int id) { Allergy oAllergy = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(AllergyDA.Get(tc, id)); if (oreader.Read()) { oAllergy = 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 oAllergy; } public Allergy Get(string sCode) { Allergy oAllergy = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(AllergyDA.Get(tc, sCode)); if (oreader.Read()) { oAllergy = 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 oAllergy; } public List Get() { List relations = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AllergyDA.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 } return relations; } public List Get(EnumStatus status) { List relations = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AllergyDA.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 } return relations; } public int Save(Allergy oAllergy) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oAllergy.IsNew) { int id = tc.GenerateID("ALLERGY", "ALLERGYID"); base.SetObjectID(oAllergy, id); AllergyDA.Insert(tc, oAllergy); } else { AllergyDA.Update(tc, oAllergy); } tc.End(); return oAllergy.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); AllergyDA.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 } }