using System; using Ease.Core.Model; using Ease.Core.DataAccess; using HRM.BO; using Ease.Core.Utility; using System.Collections.Generic; using System.Data; using Ease.Core; using Payroll.Service; namespace HRM.DA { public class MinTaxExceptionService : ServiceTemplate, IMinTaxExceptionService { #region Private functions and declaration public MinTaxExceptionService() { } private void MapObject(MinTaxException minTaxExceptions, DataReader oReader) { base.SetObjectID(minTaxExceptions, oReader.GetInt32("MinTaxExceptionID").Value); minTaxExceptions.TaxParamID = oReader.GetInt32("TaxParamID").Value; minTaxExceptions.EmployeeID = oReader.GetInt32("EmployeeID").Value; minTaxExceptions.TaxExceptionType = (EnumMinimumTaxType)oReader.GetDouble("ExceptionType").Value; minTaxExceptions.Amount = oReader.GetDouble("Amount").Value; this.SetObjectState(minTaxExceptions, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { MinTaxException minTaxExceptions = new MinTaxException(); MapObject(minTaxExceptions, oReader); return minTaxExceptions as T; } #endregion #region Service implementation public List Get() { List minTaxExceptions = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(MinTaxExceptionDA.Get(tc)); minTaxExceptions = 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 minTaxExceptions; } public MinTaxException Get(int empId) { MinTaxException minTaxException = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(MinTaxExceptionDA.Get(tc, empId)); minTaxException = 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 minTaxException; } public void Save(List minTaxExceptions) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (MinTaxException mTaxExp in minTaxExceptions) { int id = tc.GenerateID("MinTaxException", "MinTaxExceptionID"); base.SetObjectID(mTaxExp, (id)); if (MinTaxExceptionDA.IsExist(tc, mTaxExp.EmployeeID, mTaxExp.TaxParamID, mTaxExp.TaxExceptionType)) { MinTaxExceptionDA.Delete(tc, (mTaxExp.EmployeeID)); MinTaxExceptionDA.Insert(tc, mTaxExp); } else { MinTaxExceptionDA.Insert(tc, mTaxExp); } } tc.End(); } 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); MinTaxExceptionDA.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 } }