using System; using System.Data; using Ease.Core.Model; using Ease.Core.DataAccess; using Ease.Core; using System.Collections.Generic; using Ease.Core.Utility; using HRM.BO; using System.Linq; using Microsoft.AspNetCore.Localization; namespace HRM.DA { public class EmployeeAppraisalService : ServiceTemplate, IEmployeeAppraisalService { #region Object Mapping private void MapObject(EmployeeAppraisal oEmployeeAppraisal, DataReader oReader) { SetObjectID(oEmployeeAppraisal, (oReader.GetInt32("EmployeeAppraisalID").Value)); oEmployeeAppraisal.EmployeeID = oReader.GetInt32("EmployeeID", 0); oEmployeeAppraisal.AppraisalYear = (DateTime)oReader.GetDateTime("AppraisalYear"); oEmployeeAppraisal.MKTSurveyID = oReader.GetInt32("MKTSurveyID", 0); 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.GetInt32("LMID", 0); oEmployeeAppraisal.LMChangePercent = (double)oReader.GetDouble("LMChangePercent"); oEmployeeAppraisal.LMChangeAmount = (double)oReader.GetDouble("LMChangeAmount"); oEmployeeAppraisal.LMRemarks = (string)oReader.GetString("LMRemarks"); oEmployeeAppraisal.HRApproveID = oReader.GetInt32("HRApproveID", 0); 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.GetInt32("AppraisalPointID", 0); oEmployeeAppraisal.AppraisalPointRate = (double)oReader.GetDouble("AppraisalPointRate"); oEmployeeAppraisal.CreatedBy = oReader.GetInt32("CreatedBy", 0); oEmployeeAppraisal.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue ? oReader.GetDateTime("CreatedDate").Value : DateTime.MinValue; oEmployeeAppraisal.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oEmployeeAppraisal.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue ? oReader.GetDateTime("ModifiedDate").Value : (DateTime?)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 EmployeeAppraisal Get(int employeeId) { EmployeeAppraisal oEmployeeAppraisal = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(EmployeeAppraisalDA.Get(tc, employeeId)); oEmployeeAppraisal = 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 oEmployeeAppraisal; } public List Get(EnumStatus status) { List 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 List Get(DateTime apprisalYear) { List 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 List GetAppraisalDataFromObjSet(int LMId, DateTime apprisalYear) { List oEmployeeAppraisal = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(EmployeeAppraisalDA.GetAppraisalDataFromObjSet(tc, LMId, 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 List Get(int LMId, DateTime apprisalYear) { List oEmployeeAppraisal = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(EmployeeAppraisalDA.Get(tc, LMId, 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 List GetByLM(int LMId, DateTime apprisalYear) { List oEmployeeAppraisal = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(EmployeeAppraisalDA.GetByLM(tc, LMId, 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 List GetPreviouslySavedData(int LMId, DateTime apprisalYear) { List oEmployeeAppraisal = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(EmployeeAppraisalDA.GetPreviouslySavedData(tc, LMId, 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 int Save(EmployeeAppraisal item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (item.IsNew) { int id = tc.GenerateID("EmployeeAppraisal", "EmployeeAppraisalID"); SetObjectID(item, (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(List 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)); 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(int 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 } } public void DeleteByEmployeeId(int empID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); EmployeeAppraisalDA.Delete(tc, empID); 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 Save(List newItems, List oldItems, CurrentUser user) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (EmployeeAppraisal item in newItems) { if (!oldItems.Any(x => x.EmployeeID == item.EmployeeID && x.AppraisalYear.Year == item.AppraisalYear.Year)) { int id = tc.GenerateID("EmployeeAppraisal", "EmployeeAppraisalID"); SetObjectID(item, id); EmployeeAppraisalDA.Insert(tc, item); } else { EmployeeAppraisal oldData = oldItems.Where(x => x.EmployeeID == item.EmployeeID && x.AppraisalYear.Year == item.AppraisalYear.Year).FirstOrDefault(); oldData.AppraisalPointRate = item.AppraisalPointRate; oldData.ModifiedBy = user.UserID; oldData.ModifiedDate = DateTime.Now; EmployeeAppraisalDA.Update(tc, oldData); } } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion } }