using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.Core.DataAccess; using System.Data; using HRM.BO; using Ease.Core.Model; using Ease.Core.Utility; namespace HRM.DA { public class ActingResponsibilitySetupService : ServiceTemplate, IActingResponsibilitySetupService { public ActingResponsibilitySetupService() { } private void MapObject(ActingResponsibilitySetup oActingAllowSetup, DataReader oReader) { base.SetObjectID(oActingAllowSetup, oReader.GetInt32("ActingResponsibilitySetupID").Value); oActingAllowSetup.EmployeeID = oReader.GetInt32("EmployeeID").Value; oActingAllowSetup.ShiftID = oReader.GetInt32("ShiftID"); oActingAllowSetup.GradeID = oReader.GetInt32("GradeID", 0); oActingAllowSetup.WorkPlanGroupID = oReader.GetInt32("WorkPlanGroupID"); oActingAllowSetup.FromDate = oReader.GetDateTime("FromDate") == null ? DateTime.MinValue : oReader.GetDateTime("FromDate").Value; oActingAllowSetup.ToDate = oReader.GetDateTime("ToDate") == null ? DateTime.MinValue : oReader.GetDateTime("ToDate").Value; oActingAllowSetup.Remarks = oReader.GetString("Remarks"); oActingAllowSetup.EmployeeNo = oReader.GetString("EmployeeNo", true, ""); oActingAllowSetup.EmployeeName = oReader.GetString("EmployeeName", true, ""); oActingAllowSetup.Amount = oReader.GetDouble("Amount").Value; oActingAllowSetup.SalaryMonth = oReader.GetDateTime("SalaryMonth") == null ? DateTime.MinValue : oReader.GetDateTime("SalaryMonth").Value; oActingAllowSetup.ClaimWFStatus = oReader.GetInt32("CLAIMWFSTATUS") == null ? EnumClaimWFStatus.None : (EnumClaimWFStatus)oReader.GetInt32("CLAIMWFSTATUS"); oActingAllowSetup.CreatedBy = oReader.GetInt32("CreatedBy", 0); oActingAllowSetup.CreatedDate = oReader.GetDateTime("CreationDate").Value; oActingAllowSetup.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oActingAllowSetup.ModifiedDate = oReader.GetDateTime("ModifiedDate"); oActingAllowSetup.IsHoliday = oReader.GetBoolean("ISHOLIDAY", false); this.SetObjectState(oActingAllowSetup, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { ActingResponsibilitySetup oActingAllowSetup = new ActingResponsibilitySetup(); MapObject(oActingAllowSetup, oReader); return oActingAllowSetup as T; } #region Service Implementation public List GetWithPayrollType(int payrollTypeID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ActingResponsibilitySetupDA.GetWithPayrollType(tc, payrollTypeID)); var actingAllowSetups = this.CreateObjects(dr); dr.Close(); tc.End(); return actingAllowSetups; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List GetAllTemporaryShiftEmployee() { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ActingResponsibilitySetupDA.GetAllTemporaryShiftEmployee(tc)); var tempShiftEmployees = this.CreateObjects(dr); dr.Close(); tc.End(); return tempShiftEmployees; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public DataSet GetByLineManager(int lineManagerid) { DataSet DATA = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DATA = ActingResponsibilitySetupDA.GetByLineManager(tc, lineManagerid); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return DATA; } public List GetAllTemporaryShiftEmployeeByLM(int empID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ActingResponsibilitySetupDA.GetAllTemporaryShiftEmployeeByLM(tc, empID)); var tempShiftEmployees = this.CreateObjects(dr); dr.Close(); tc.End(); return tempShiftEmployees; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List GetTemporaryShiftEmployee(DateTime attnDate, int employeeID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ActingResponsibilitySetupDA.GetTemporaryShiftEmployee(tc, attnDate, employeeID)); var tempShiftEmployees = this.CreateObjects(dr); dr.Close(); tc.End(); return tempShiftEmployees; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List GetTemporaryShiftEmployee() { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ActingResponsibilitySetupDA.GetTemporaryShiftEmployee(tc)); var tempShiftEmployees = this.CreateObjects(dr); dr.Close(); tc.End(); return tempShiftEmployees; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } // Get Only Approved Shift Change public List GetTemporaryShiftEmployee(DateTime attnDate) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ActingResponsibilitySetupDA.GetTemporaryShiftEmployee(tc, attnDate)); var tempShiftEmployees = this.CreateObjects(dr); dr.Close(); tc.End(); return tempShiftEmployees; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List GetBySalaryMonth(DateTime fromDate, int payrollTypeID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ActingResponsibilitySetupDA.GetBySalaryMonth(tc, fromDate, payrollTypeID)); var actingAllowSetups = this.CreateObjects(dr); dr.Close(); tc.End(); return actingAllowSetups; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public ActingResponsibilitySetup GetTempShiftByID(int id) { TransactionContext tc = null; try { var oTempShift = new ActingResponsibilitySetup(); tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ActingResponsibilitySetupDA.GetTempShiftByID(tc, id)); if (oreader.Read()) { oTempShift = this.CreateObject(oreader); } oreader.Close(); tc.End(); return oTempShift; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List GetByEmpID(DateTime fromDate, DateTime toDate, int empid) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ActingResponsibilitySetupDA.GetbyEmpID(tc, fromDate, toDate,empid)); var actingAllowSetups = this.CreateObjects(dr); dr.Close(); tc.End(); return actingAllowSetups; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List Get(DateTime fromDate, DateTime toDate, int empid, EnumClaimWFStatus enumClaimWFStatus) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ActingResponsibilitySetupDA.Get(tc, fromDate, toDate, empid, enumClaimWFStatus)); var actingAllowSetups = this.CreateObjects(dr); dr.Close(); tc.End(); return actingAllowSetups; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List GetForApprove(DateTime fromDate, DateTime toDate, int lmId, EnumClaimWFStatus enumClaimWFStatus) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ActingResponsibilitySetupDA.GetForApprove(tc, fromDate, toDate, lmId, enumClaimWFStatus)); var actingAllowSetups = this.CreateObjects(dr); dr.Close(); tc.End(); return actingAllowSetups; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List Get(DateTime fromDate, DateTime toDate, int payrolltypeID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ActingResponsibilitySetupDA.Get(tc, fromDate, toDate,payrolltypeID)); var actingAllowSetups = this.CreateObjects(dr); dr.Close(); tc.End(); return actingAllowSetups; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List GetByStatus(DateTime fromDate, DateTime toDate, int payrolltypeID, EnumClaimWFStatus enumClaimWFStatus) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ActingResponsibilitySetupDA.GetByStatus(tc, fromDate, toDate, payrolltypeID, enumClaimWFStatus)); var actingAllowSetups = this.CreateObjects(dr); dr.Close(); tc.End(); return actingAllowSetups; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List GetOnwardByEmpID(DateTime fromDate, int employeeid) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ActingResponsibilitySetupDA.GetOnwardByEmpID(tc, fromDate, employeeid)); var actingAllowSetups = this.CreateObjects(dr); dr.Close(); tc.End(); return actingAllowSetups; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List Get(int employeeID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ActingResponsibilitySetupDA.Get(tc, employeeID)); var actingAllowSetups = this.CreateObjects(dr); dr.Close(); tc.End(); return actingAllowSetups; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public bool IsEmployeeExistOnSameDate(int empID, DateTime fromDate) { bool isExist = false; TransactionContext tc = null; try { tc = TransactionContext.Begin(); isExist = ActingResponsibilitySetupDA.IsEmployeeExistOnSameDate(tc, empID, fromDate); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return isExist; } public bool IsEmployeeExist(int empID, DateTime fromDate, DateTime toDate) { bool isExist = false; TransactionContext tc = null; try { tc = TransactionContext.Begin(); isExist = ActingResponsibilitySetupDA.IsEmployeeExist(tc, empID, fromDate, toDate); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return isExist; } public int Save(ActingResponsibilitySetup actingAllowSetup) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (actingAllowSetup.IsNew) { int id = tc.GenerateID("ActingResponsibilitySetup", "ActingResponsibilitySetupID"); actingAllowSetup.ID = id; ActingResponsibilitySetupDA.Insert(tc, actingAllowSetup); } else { ActingResponsibilitySetupDA.Update(tc, actingAllowSetup); } tc.End(); return actingAllowSetup.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 actingAllowSetups) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id = tc.GenerateID("ActingResponsibilitySetup", "ActingResponsibilitySetupID"); actingAllowSetups.ForEach(actingAllowSetup => { if (actingAllowSetup.IsNew) { actingAllowSetup.ID = id; ActingResponsibilitySetupDA.Delete(tc, actingAllowSetup.EmployeeID, actingAllowSetup.FromDate, actingAllowSetup.ToDate); ActingResponsibilitySetupDA.Insert(tc, actingAllowSetup); } else { ActingResponsibilitySetupDA.Update(tc, actingAllowSetup); } id = id + 1; }); 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); ActingResponsibilitySetupDA.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 } } ActingResponsibilitySetup IActingResponsibilitySetupService.Get(int Id) { ActingResponsibilitySetup oActingResponsibilitySetup = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ActingResponsibilitySetupDA.GetById(tc, Id)); if (oreader.Read()) { oActingResponsibilitySetup = 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 oActingResponsibilitySetup; } public int GetTotalDayOff(int empId, DateTime fromDate, DateTime toDate) { int totalDayOff = 0; TransactionContext tc = null; try { tc = TransactionContext.Begin(); totalDayOff = ActingResponsibilitySetupDA.GetTotalDayOff(tc, empId, fromDate, toDate); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return totalDayOff; } public void SaveTemporaryShift(UpdateRosterModel oUpdateRosterModel) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oUpdateRosterModel.GetEmpIds() == string.Empty) { throw new Exception("Please Select Employee First"); } ActingResponsibilitySetupDA.SaveTemporaryShift(tc, oUpdateRosterModel); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } internal void UpdateTempShiftToDate(TransactionContext tc, int employeeID, DateTime effectDate) { List actingAllowSetups = new List(); try { DataReader dr = new DataReader(ActingResponsibilitySetupDA.GetByEmployeeID(tc, employeeID, effectDate)); actingAllowSetups = this.CreateObjects(dr); dr.Close(); if (actingAllowSetups.Count > 0) { DateTime dt = effectDate.AddDays(-1); foreach (ActingResponsibilitySetup osetup in actingAllowSetups) { ActingResponsibilitySetupDA.Update(tc, osetup, dt); } } } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion } }