using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using HRM.BO; namespace HRM.DA { public class BadliProcessService : ServiceTemplate { public BadliProcessService() { } private void MapObject(BadliProcess oBadliProcess, DataReader oReader) { base.SetObjectID(oBadliProcess, (oReader.GetInt32("BadliProcessID").Value)); oBadliProcess.FromDate = oReader.GetDateTime("FromDate").Value; oBadliProcess.ToDate = oReader.GetDateTime("ToDate").Value; oBadliProcess.WorkPlanGroupID = oReader.GetInt32("WorkPlanGroupID", 0); oBadliProcess.ProcessDate = oReader.GetDateTime("ProcessDate").Value; oBadliProcess.Description = oReader.GetString("Description"); oBadliProcess.ProcessCode = oReader.GetString("ProcessCode"); oBadliProcess.CreatedBy = oReader.GetInt32("CreatedBy", 0); oBadliProcess.CreatedDate = oReader.GetDateTime("CreationDate").Value; oBadliProcess.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oBadliProcess.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oBadliProcess, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { BadliProcess oBadliProcess = new BadliProcess(); MapObject(oBadliProcess, oReader); return oBadliProcess as T; } #region ServiceImplementation public List Get() { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BadliProcessDA.Get(tc)); var oBadliProcesss = this.CreateObjects(dr); dr.Close(); tc.End(); return oBadliProcesss; } 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 processDate) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BadliProcessDA.Get(tc, processDate)); var oBadliProcesss = this.CreateObjects(dr); dr.Close(); tc.End(); return oBadliProcesss; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public DateTime GetLastProcessDate() { DateTime lastProcessDate = DateTime.MinValue; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(BadliProcessDA.GetLastProcessDate(tc)); if (oreader.Read()) { lastProcessDate = oreader.GetDateTime("LastProcessDate").HasValue ? oreader.GetDateTime("LastProcessDate").Value : DateTime.Now; } 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 lastProcessDate; } public List Get(DateTime processDate, int WorkPlanGroupID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BadliProcessDA.Get(tc, processDate, WorkPlanGroupID)); var oBadliProcesss = this.CreateObjects(dr); dr.Close(); tc.End(); return oBadliProcesss; } 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) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BadliProcessDA.Get(tc, fromDate, toDate)); var oBadliProcesss = this.CreateObjects(dr); dr.Close(); tc.End(); return oBadliProcesss; } 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 WorkPlanGroupID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BadliProcessDA.Get(tc, fromDate, toDate, WorkPlanGroupID)); var oBadliProcesss = this.CreateObjects(dr); dr.Close(); tc.End(); return oBadliProcesss; } 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 WorkPlanGroupID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BadliProcessDA.Get(tc, WorkPlanGroupID)); var oBadliProcesss = this.CreateObjects(dr); dr.Close(); tc.End(); return oBadliProcesss; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List Get(string WorkPlanGroupIDs) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BadliProcessDA.Get(tc, WorkPlanGroupIDs)); var oBadliProcesss = this.CreateObjects(dr); dr.Close(); tc.End(); return oBadliProcesss; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Save(BadliProcess oBadliProcess, List oBadliDailyPayments, List oBadliDailyRecruits) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id = tc.GenerateID("BadliProcess", "BadliProcessID"); base.SetObjectID(oBadliProcess, (id)); if (BadliProcessDA.IsExist(tc, oBadliProcess.WorkPlanGroupID, oBadliProcess.FromDate)) { BadliProcessDA.Delete(tc, oBadliProcess.WorkPlanGroupID, oBadliProcess.FromDate); } BadliProcessDA.Insert(tc, oBadliProcess); oBadliDailyPayments.ForEach(x => x.BadliProcessID = (id)); oBadliDailyRecruits.ForEach(x => x.IsPaid = true); (new BadliDailyPaymentService()).Save(oBadliDailyPayments, tc); (new BadliDailyRecruitService()).Save(oBadliDailyRecruits, tc); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion } }