using HRM.BO; using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using System; using System.Collections.Generic; using System.Data; namespace HRM.DA { public class RewardStatementService : ServiceTemplate, IRewardStatementService { private void MapObject(RewardStatement rewardStatement, DataReader oReader) { base.SetObjectID(rewardStatement, (oReader.GetInt32("RewardStatementID").Value)); rewardStatement.Name = oReader.GetString("Name"); rewardStatement.RewardStatementType = (EnumRewardStatement)oReader.GetInt32("RewardStatementType").GetValueOrDefault(); rewardStatement.ComponentID = oReader.GetInt32("ComponentID", 0); rewardStatement.ComponentType = (enumPayrollComponentType)oReader.GetInt32("ComponentType").GetValueOrDefault(); rewardStatement.Description = oReader.GetString("Description"); rewardStatement.CreatedBy = oReader.GetInt32("CreatedBy", 0); rewardStatement.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue ? oReader.GetDateTime("CreatedDate").Value : DateTime.MinValue; rewardStatement.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); rewardStatement.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue ? oReader.GetDateTime("ModifiedDate").Value : (DateTime?)null; this.SetObjectState(rewardStatement, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { RewardStatement rewardStatement = new RewardStatement(); MapObject(rewardStatement, oReader); return rewardStatement as T; } #region Service implementation public List Get() { List rewardStatements = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(RewardStatementDA.Get(tc)); rewardStatements = 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 rewardStatements; } public List Get(EnumRewardStatement rewardStatementType) { List rewardStatements = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(RewardStatementDA.Get(tc, rewardStatementType)); rewardStatements = 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 rewardStatements; } public RewardStatement Get(int rewardStatementID) { RewardStatement rewardStatement = new RewardStatement(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(RewardStatementDA.Get(tc, rewardStatementID)); if (dr.Read()) rewardStatement = this.CreateObject(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 rewardStatement; } public void Save(RewardStatement rewardStatement) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (rewardStatement.IsNew) { int id = tc.GenerateID("RewardStatement", "RewardStatementID"); base.SetObjectID(rewardStatement, (id)); RewardStatementDA.Insert(tc, rewardStatement); } else { RewardStatementDA.Update(tc, rewardStatement); } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new Exception("Failed to Component Upload Setup. Because " + e.Message, e); #endregion } } public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); RewardStatementDA.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 } }