using System; using System.Data; using System.Linq; using Ease.CoreV35; using Ease.CoreV35.Model; using Ease.CoreV35.DataAccess; using System.Collections.Generic; using Payroll.BO; using Ease.CoreV35.Caching; namespace Payroll.Service { #region OpiParameterIndividual Service [Serializable] public class OpiParameterIndividualService : ServiceTemplate, IOpiParameterIndividualService { #region Private functions and declaration Cache _cache = new Cache(typeof(OpiParameterIndividual)); public OpiParameterIndividualService() { } private void MapObject(OpiParameterIndividual oOpiIndividual, DataReader oReader) { base.SetObjectID(oOpiIndividual, oReader.GetID("OpiParameterIndividualID")); oOpiIndividual.ArrearType = (EnumArrearType)oReader.GetInt32("ArrearType"); oOpiIndividual.EmployeeId = oReader.GetID("EmployeeId"); oOpiIndividual.FromDate = oReader.GetDateTime("FromDate").Value; oOpiIndividual.ToDate = oReader.GetDateTime("ToDate"); oOpiIndividual.IndividualType = (EnumOPIIndivdualType)oReader.GetInt32("IndividualType"); oOpiIndividual.OpiItemId = oReader.GetID("OpiItemId"); oOpiIndividual.OpiParameterID = oReader.GetID("OpiParameterId"); oOpiIndividual.OpiPeriodicity = (EnumOpiPeriodicity)oReader.GetInt32("OpiPeriodicity"); oOpiIndividual.Value = oReader.GetDouble("Value").Value; oOpiIndividual.ValueType = (EnumValueType)oReader.GetInt32("ValueType"); oOpiIndividual.CreatedBy = oReader.GetID("CreatedBy"); oOpiIndividual.CreatedDate = oReader.GetDateTime("CreationDate").Value; oOpiIndividual.ModifiedBy = oReader.GetID("ModifiedBy"); oOpiIndividual.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oOpiIndividual, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { OpiParameterIndividual oOpiIndividual = new OpiParameterIndividual(); MapObject(oOpiIndividual, oReader); return oOpiIndividual as T; } protected OpiParameterIndividual CreateObject(DataReader oReader) { OpiParameterIndividual oOpiIndividual = new OpiParameterIndividual(); MapObject(oOpiIndividual, oReader); return oOpiIndividual; } #endregion #region Service implementation public OpiParameterIndividual Get(ID id) { OpiParameterIndividual oOpiIndividual = new OpiParameterIndividual(); #region Cache Header oOpiIndividual = (OpiParameterIndividual)_cache["Get", id]; if (oOpiIndividual != null) return oOpiIndividual; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(OpiParameterIndividualDA.Get(tc, id)); if (oreader.Read()) { oOpiIndividual = 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 } #region Cache Footer _cache.Add(oOpiIndividual, "Get", id); #endregion return oOpiIndividual; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate oOpiIndividuals = _cache["Get"] as ObjectsTemplate; if (oOpiIndividuals != null) return oOpiIndividuals; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(OpiParameterIndividualDA.Get(tc)); oOpiIndividuals = this.CreateObjects(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 } #region Cache Footer _cache.Add(oOpiIndividuals, "Get"); #endregion return oOpiIndividuals; } public ObjectsTemplate GetByParameterID(ID nParamaterID) { #region Cache Header ObjectsTemplate oOpiIndividuals = _cache["GetByParameterID"] as ObjectsTemplate; if (oOpiIndividuals != null) return oOpiIndividuals; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(OpiParameterIndividualDA.GetByParameterID(tc, nParamaterID)); oOpiIndividuals = this.CreateObjects(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 } #region Cache Footer _cache.Add(oOpiIndividuals, "GetByParameterID"); #endregion return oOpiIndividuals; } public ObjectsTemplate Get(DateTime fromDate, DateTime toDate) { ObjectsTemplate opiParameterIndividuals = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OpiParameterIndividualDA.Get(tc, fromDate, toDate)); opiParameterIndividuals = 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 opiParameterIndividuals; } public ObjectsTemplate GetIndividuals(ID nOpiPAramID, EnumOPIIndivdualType type) { #region Cache Header ObjectsTemplate opiParamIndividuals = _cache["GetIndividuals", nOpiPAramID, type] as ObjectsTemplate; if (opiParamIndividuals != null) return opiParamIndividuals; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OpiParameterIndividualDA.GetIndividuals(tc, nOpiPAramID, type)); opiParamIndividuals = 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 } #region Cache Footer _cache.Add(opiParamIndividuals, "GetIndividuals", nOpiPAramID, type); #endregion return opiParamIndividuals; } public ID Save(OpiParameterIndividual oOpiIndividual, ID payrollTypeID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oOpiIndividual.IsNew) { int id = tc.GenerateID("OpiParameterIndividual", "OpiParameterIndividualID"); base.SetObjectID(oOpiIndividual, ID.FromInteger(id)); OpiParameterIndividualDA.Insert(tc, oOpiIndividual, payrollTypeID); } else { OpiParameterIndividualDA.Update(tc, oOpiIndividual, payrollTypeID); } return oOpiIndividual.ID; tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to GetOpiParameterIndividual", e); #endregion } } public void BulkSave(ObjectsTemplate oParamIndvdls, ID payrollTypeID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (var oOpiIndividual in oParamIndvdls) { if (oOpiIndividual.IsNew) { int id = tc.GenerateID("OpiParameterIndividual", "OpiParameterIndividualID"); base.SetObjectID(oOpiIndividual, ID.FromInteger(id)); OpiParameterIndividualDA.Insert(tc, oOpiIndividual, payrollTypeID); } else { OpiParameterIndividualDA.Update(tc, oOpiIndividual, payrollTypeID); } } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to GetOpiParameterIndividual", e); #endregion } } public void Delete(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); OpiParameterIndividualDA.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 #region IOpiParameterIndividualService Members #endregion } #endregion }