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; using System.Linq; namespace HRM.DA { public class ITEmpHeadService : ServiceTemplate, IITEmpHeadService { private EmployeeService employeeService = new EmployeeService(); public ITEmpHeadService() { } private void MapObject(ITEmpHead oITEmpHead, DataReader oReader) { base.SetObjectID(oITEmpHead, oReader.GetInt32("ITEMPHEADID").Value); oITEmpHead.EmployeeID = oReader.GetInt32("EmployeeID", 0); oITEmpHead.EmployeeNoView = oReader.GetString("EmployeeNo", string.Empty); oITEmpHead.EmployeeNameView = oReader.GetString("Name", string.Empty); oITEmpHead.HeadID = (EnumIncomeTaxHead)oReader.GetInt32("HEADID"); oITEmpHead.StartDate = oReader.GetDateTime("STARTDATE").Value; oITEmpHead.EndDate = oReader.GetDateTime("ENDDATE").Value; oITEmpHead.HouseRent = oReader.GetDouble("HOUSERENT").Value; oITEmpHead.CreatedBy = oReader.GetInt32("CreatedBy", 0); oITEmpHead.CreatedDate = oReader.GetDateTime("CreationDate").Value; oITEmpHead.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oITEmpHead.ModifiedDate = oReader.GetDateTime("ModifiedDate"); oITEmpHead.TaxparamID = oReader.GetInt32("TaxparamID", 0); this.SetObjectState(oITEmpHead, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { ITEmpHead oITEmpHead = new ITEmpHead(); MapObject(oITEmpHead, oReader); return oITEmpHead as T; } #region Service implementation public ITEmpHead Get(int id) { ITEmpHead oITEmpHead = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ITEmpHeadDA.Get(tc, id)); if (oreader.Read()) { oITEmpHead = 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 oITEmpHead; } public List GetWithTaxParam(int taxparamID) { List ITEmpHeads = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); ITEmpHeads= this.GetWithTaxParam(tc, taxparamID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return ITEmpHeads; } public List GetWithTaxParam(TransactionContext tc, int taxparamID) { List ITEmpHeads = new List(); try { DataReader dr = new DataReader(ITEmpHeadDA.GetWithTaxParam(tc, taxparamID)); ITEmpHeads = this.CreateObjects(dr); dr.Close(); } catch (Exception e) { } return ITEmpHeads; } public int Save(ITEmpHead oITEmpHead) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oITEmpHead.IsNew) { int id = tc.GenerateID("ITEmpHead", "ITEMPHEADID"); base.SetObjectID(oITEmpHead, (id)); ITEmpHeadDA.Insert(tc, oITEmpHead); } else { ITEmpHeadDA.Update(tc, oITEmpHead); } tc.End(); return oITEmpHead.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public int Save2(ITEmpHead oITEmpHead) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id = tc.GenerateID("ITEmpHead", "ITEMPHEADID"); base.SetObjectID(oITEmpHead, (id)); ITEmpHeadDA.Insert(tc, oITEmpHead); tc.End(); return oITEmpHead.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(ITEmpHead Item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ITEmpHeadDA.Delete(tc, Item); 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 Private Finctions public List Get(List ITEmpHeads, int employeeId) { var ReturnItems = from item in ITEmpHeads where item.EmployeeID == employeeId select item; List Items = new List(); foreach (ITEmpHead oi in ReturnItems) { Items.Add(oi); } return Items; } #endregion Private Finctions } }