using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using HRM.BO; namespace HRM.DA { [Serializable] public class AttendanceWFHistoryService : ServiceTemplate, IAttendanceWFHistoryService { private void MapObject(AttendanceWFHistory oAttendanceWFHistory, DataReader oReader) { base.SetObjectID(oAttendanceWFHistory, oReader.GetInt32("AttnWFHistoryID").Value); oAttendanceWFHistory.EmployeeID = (oReader.GetInt32("EmployeeID").Value); oAttendanceWFHistory.DailyAttnProcessID = (oReader.GetInt32("DAILYATTNPROCESSID").Value); oAttendanceWFHistory.WFStatus = (EnumWFAttnStatus)oReader.GetInt32("WFStatus").Value; oAttendanceWFHistory.OTHour = oReader.GetDouble("OTHour").HasValue ? oReader.GetDouble("OTHour").Value : 0; oAttendanceWFHistory.Remarks = oReader.GetString("Remarks"); oAttendanceWFHistory.AttandanceStatus = (EnumAttendanceType)oReader.GetInt32("AttnStatus").Value; this.SetObjectState(oAttendanceWFHistory, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { AttendanceWFHistory oAttendanceWFHistory = new AttendanceWFHistory(); MapObject(oAttendanceWFHistory, oReader); return oAttendanceWFHistory as T; } protected AttendanceWFHistory CreateObject(DataReader oReader) { AttendanceWFHistory oAttendanceWFHistory = new AttendanceWFHistory(); MapObject(oAttendanceWFHistory, oReader); return oAttendanceWFHistory; } public int Save(AttendanceWFHistory oAttendanceWFHistory, TransactionContext tc) { try { if (oAttendanceWFHistory.IsNew) { int id = tc.GenerateID("ATTNWFHISTORY", "AttnWFHistoryID"); base.SetObjectID(oAttendanceWFHistory, id); AttendanceWFHistoryDA.Insert(tc, oAttendanceWFHistory); } else { AttendanceWFHistoryDA.Update(tc, oAttendanceWFHistory); } return oAttendanceWFHistory.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public int Save(AttendanceWFHistory oAttendanceWFHistory) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oAttendanceWFHistory.IsNew) { int id = tc.GenerateID("ATTNWFHISTORY", "AttnWFHistoryID"); base.SetObjectID(oAttendanceWFHistory, id); AttendanceWFHistoryDA.Insert(tc, oAttendanceWFHistory); } else { AttendanceWFHistoryDA.Update(tc, oAttendanceWFHistory); } tc.End(); return oAttendanceWFHistory.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(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); AttendanceWFHistoryDA.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 AttendanceWFHistory Get(int id) { AttendanceWFHistory oAttendanceWFHistory = new AttendanceWFHistory(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(AttendanceWFHistoryDA.Get(tc, id)); if (oreader.Read()) { oAttendanceWFHistory = this.CreateObject(oreader); } oreader.Close(); tc.End(); return oAttendanceWFHistory; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List GetByEmpID(int nemployeeID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AttendanceWFHistoryDA.Get(tc, nemployeeID)); var attendanceWFHistories = this.CreateObjects(dr); dr.Close(); tc.End(); return attendanceWFHistories; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } } }