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 TaxHeadAssignment Service [Serializable] public class TaxHeadAssignmentService : ServiceTemplate, ITaxHeadAssignmentService { #region Private functions and declaration Cache _cache = new Cache(typeof(TaxHeadAssignment)); #endregion public TaxHeadAssignmentService() { } private void MapObject(TaxHeadAssignment oTaxHeadAssignment, DataReader oReader) { base.SetObjectID(oTaxHeadAssignment, oReader.GetID("HeadID")); //oTaxHeadAssignment.HeadType = oReader.GetInt32("headType").Value; oTaxHeadAssignment.Description = oReader.GetString("description"); oTaxHeadAssignment.DeductPercent = oReader.GetDouble("deductPercent").Value; oTaxHeadAssignment.Sequence = oReader.GetInt32("SequenceNO").Value; oTaxHeadAssignment.Status =(EnumStatus) oReader.GetInt32("Status").Value; oTaxHeadAssignment.CreatedBy = oReader.GetID("CreatedBy"); oTaxHeadAssignment.CreatedDate =oReader.GetDateTime("CreationDate")==null?DateTime.MinValue:oReader.GetDateTime("CreationDate").Value; oTaxHeadAssignment.ModifiedBy = oReader.GetID("ModifiedBy"); oTaxHeadAssignment.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oTaxHeadAssignment, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { TaxHeadAssignment oTaxHeadAssignment = new TaxHeadAssignment(); MapObject(oTaxHeadAssignment, oReader); return oTaxHeadAssignment as T; } protected TaxHeadAssignment CreateObject(DataReader oReader) { TaxHeadAssignment oTaxHeadAssignment = new TaxHeadAssignment(); MapObject(oTaxHeadAssignment, oReader); return oTaxHeadAssignment; } #region Service implementation public TaxHeadAssignment Get(ID id) { TaxHeadAssignment oTaxHeadAssignment = new TaxHeadAssignment(); #region Cache Header oTaxHeadAssignment = _cache["Get", id] as TaxHeadAssignment; if (oTaxHeadAssignment != null) return oTaxHeadAssignment; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TaxHeadAssignmentDA.Get(tc, id)); if (oreader.Read()) { oTaxHeadAssignment = 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(oTaxHeadAssignment, "Get", id); #endregion return oTaxHeadAssignment; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate taxHeadAssignments = _cache["Get"] as ObjectsTemplate; if (taxHeadAssignments != null) return taxHeadAssignments; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(TaxHeadAssignmentDA.Get(tc)); taxHeadAssignments = 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(taxHeadAssignments, "Get"); #endregion return taxHeadAssignments; } public ID Save(TaxHeadAssignment oTaxHeadAssignment) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oTaxHeadAssignment.IsNew) { int id = tc.GenerateID("INCOMETAXHEAD", "HeadID"); base.SetObjectID(oTaxHeadAssignment, ID.FromInteger(id)); TaxHeadAssignmentDA.Insert(tc, oTaxHeadAssignment); } else { TaxHeadAssignmentDA.Update(tc, oTaxHeadAssignment); } tc.End(); return oTaxHeadAssignment.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(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); TaxHeadAssignmentDA.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 }