using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35.Model; using Payroll.BO; using Ease.CoreV35.DataAccess; using Ease.CoreV35; namespace Payroll.Service { public class EmployeeAppraisalService : ServiceTemplate, IEmployeeAppraisalService { #region Object Mapping private void MapObject(EmployeeAppraisal oEmployeeAppraisal, DataReader oReader) { SetObjectID(oEmployeeAppraisal, oReader.GetID("EmployeeAppraisalID")); oEmployeeAppraisal.EmployeeID = oReader.GetID("EmployeeID"); oEmployeeAppraisal.AppraisalYear = (DateTime)oReader.GetDateTime("AppraisalYear"); oEmployeeAppraisal.MKTSurveyID = oReader.GetID("MKTSurveyID"); oEmployeeAppraisal.CurrentBasic = (double)oReader.GetDouble("CurrentBasic"); oEmployeeAppraisal.SurveyON = (EnumSurveyOn)oReader.GetInt32("SurveyON"); oEmployeeAppraisal.BudgetAmount = (double)oReader.GetDouble("BudgetAmount"); oEmployeeAppraisal.MKTAmount = (double)oReader.GetDouble("MKTAmount"); oEmployeeAppraisal.LMID = oReader.GetID("LMID"); oEmployeeAppraisal.LMChangePercent = (double)oReader.GetDouble("LMChangePercent"); oEmployeeAppraisal.LMChangeAmount = (double)oReader.GetDouble("LMChangeAmount"); oEmployeeAppraisal.LMRemarks = (string)oReader.GetString("LMRemarks"); oEmployeeAppraisal.HRApproveID = oReader.GetID("HRApproveID"); oEmployeeAppraisal.HRChangePercent = (double)oReader.GetDouble("HRChangePercent"); oEmployeeAppraisal.HRChangeAmount = (double)oReader.GetDouble("HRChangeAmount"); oEmployeeAppraisal.HRRemarks = (string)oReader.GetString("HRRemarks"); oEmployeeAppraisal.ISLMDone = (bool)oReader.GetBoolean("ISLMDone"); oEmployeeAppraisal.ISHRDone = (bool)oReader.GetBoolean("ISHRDone"); oEmployeeAppraisal.AppraisalPointID = oReader.GetID("AppraisalPointID"); oEmployeeAppraisal.AppraisalPointRate = (double)oReader.GetDouble("AppraisalPointRate"); if (oReader.GetDateTime("CreatedDate") != null) { oEmployeeAppraisal.CreatedDate = (DateTime)oReader.GetDateTime("CreatedDate"); } else oEmployeeAppraisal.CreatedDate = DateTime.MinValue; if (oReader.GetDateTime("ModifiedDate") != null) { oEmployeeAppraisal.ModifiedDate = (DateTime)oReader.GetDateTime("ModifiedDate"); } else oEmployeeAppraisal.ModifiedDate = null; if (oReader.GetInt32("CreatedBy") != null) { oEmployeeAppraisal.CreatedBy = oReader.GetID("CreatedBy"); } else oEmployeeAppraisal.CreatedBy = null; if (oReader.GetInt32("ModifiedBy") != null) { oEmployeeAppraisal.ModifiedBy = oReader.GetID("ModifiedBy"); } else oEmployeeAppraisal.ModifiedBy = null; this.SetObjectState(oEmployeeAppraisal, ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { EmployeeAppraisal oEmployeeAppraisal = new EmployeeAppraisal(); MapObject(oEmployeeAppraisal, oReader); return oEmployeeAppraisal as T; } #endregion #region Service Implementation public ObjectsTemplate Get(DateTime apprisalYear) { ObjectsTemplate oEmployeeAppraisal = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(EmployeeAppraisalDA.Get(tc, apprisalYear)); oEmployeeAppraisal = 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 } return oEmployeeAppraisal; } public ObjectsTemplate Get(EnumStatus status) { ObjectsTemplate oEmployeeAppraisal = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(EmployeeAppraisalDA.Get(tc, status)); oEmployeeAppraisal = 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 } return oEmployeeAppraisal; } public ID Save(EmployeeAppraisal item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (item.IsNew) { int id = tc.GenerateID("EmployeeAppraisal", "EmployeeAppraisalID"); SetObjectID(item, ID.FromInteger(id)); EmployeeAppraisalDA.Insert(tc, item); } else { EmployeeAppraisalDA.Update(tc, item); } tc.End(); return item.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Save(ObjectsTemplate items) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (EmployeeAppraisal item in items) { if (item.IsNew) { int id = tc.GenerateID("EmployeeAppraisal", "EmployeeAppraisalID"); SetObjectID(item, ID.FromInteger(id)); EmployeeAppraisalDA.Insert(tc, item); } else { EmployeeAppraisalDA.Update(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 } } public void Delete(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); EmployeeAppraisalDA.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 } }