using HRM.BO; using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using System; using System.Collections.Generic; using System.Linq; namespace HRM.DA { #region WeeklyHoliday Service public class WeeklyHolidayService : ServiceTemplate, IWeeklyHolidayService { public WeeklyHolidayService() { } private void MapObject(WeeklyHoliday oWeeklyHoliday, DataReader oReader) { base.SetObjectID(oWeeklyHoliday, oReader.GetInt32("WeeklyHolidayID").Value); oWeeklyHoliday.DateType = oReader.GetInt16("DateType").Value; oWeeklyHoliday.LocationID = oReader.GetInt32("LocationID"); oWeeklyHoliday.Sequence = oReader.GetInt32("SequenceNo").Value; oWeeklyHoliday.Status = (EnumStatus)oReader.GetInt32("Status").Value; oWeeklyHoliday.HolidayMonth = oReader.GetInt32("HolidayMonth").GetValueOrDefault(); oWeeklyHoliday.IsAlternative = oReader.GetBoolean("IsAlternative").GetValueOrDefault(); oWeeklyHoliday.IsHalfDay = oReader.GetBoolean("IsHalfDay").GetValueOrDefault(); oWeeklyHoliday.CreatedBy = oReader.GetInt32("CreatedBy", 0); oWeeklyHoliday.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oWeeklyHoliday.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oWeeklyHoliday.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oWeeklyHoliday, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { WeeklyHoliday oWeeklyHoliday = new WeeklyHoliday(); MapObject(oWeeklyHoliday, oReader); return oWeeklyHoliday as T; } #region Service implementation public WeeklyHoliday Get(int id) { WeeklyHoliday oWeeklyHoliday = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(WeeklyHolidayDA.Get(tc, id)); if (oreader.Read()) { oWeeklyHoliday = 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 oWeeklyHoliday; } public List Get(EnumStatus status) { List WeeklyHolidays = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WeeklyHolidayDA.Get(tc, status)); WeeklyHolidays = this.CreateObjects(dr); dr.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 WeeklyHolidays; } public List GetCompanyEntireHolidays() { List WeeklyHolidays = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WeeklyHolidayDA.GetCompanyEntireHolidays(tc)); WeeklyHolidays = this.CreateObjects(dr); dr.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 WeeklyHolidays; } public List GetByLocation(int LocID) { List WeeklyHolidays = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WeeklyHolidayDA.GetByLocation(tc, LocID)); WeeklyHolidays = this.CreateObjects(dr); dr.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 WeeklyHolidays; } public List GetByEmployee(int EmpID) { List WeeklyHolidays = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WeeklyHolidayDA.GetByEmployee(tc, EmpID)); WeeklyHolidays = this.CreateObjects(dr); dr.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 WeeklyHolidays; } public int Save(WeeklyHoliday oWeeklyHoliday) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oWeeklyHoliday.IsNew) { int id = tc.GenerateID("WeeklyHoliday", "WeeklyHolidayID"); base.SetObjectID(oWeeklyHoliday, id); int seqNo = tc.GenerateID("WeeklyHoliday", "SequenceNo"); oWeeklyHoliday.Sequence = seqNo; WeeklyHolidayDA.Insert(tc, oWeeklyHoliday); } else { WeeklyHolidayDA.Update(tc, oWeeklyHoliday); } tc.End(); return oWeeklyHoliday.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 oWeeklyHolidays) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id = tc.GenerateID("WeeklyHoliday", "WeeklyHolidayID"); foreach (WeeklyHoliday item in oWeeklyHolidays) { if (item.IsNew) { base.SetObjectID(item, id); int seqNo = tc.GenerateID("WeeklyHoliday", "SequenceNo"); item.Sequence = seqNo; item.CreatedBy = item.CreatedBy; item.CreatedDate = DateTime.Now; WeeklyHolidayDA.Insert(tc, item); id++; } else { item.ModifiedBy = item.ModifiedBy; item.ModifiedDate = DateTime.Now; WeeklyHolidayDA.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); WeeklyHolidayDA.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 } #endregion }