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