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; namespace HRM.DA { public class RecognitionService : ServiceTemplate, IRecognitionService { #region Constructor public RecognitionService() { } #endregion #region MapObjects private void MapObject(Recognition oRecognition, DataReader oReader) { base.SetObjectID(oRecognition, (oReader.GetInt32("RecognitionID").Value)); oRecognition.NominateBy = oReader.GetInt32("NominateBy", 0); oRecognition.NominateDate = oReader.GetDateTime("NominateDate").Value; oRecognition.SalaryMonth = oReader.GetDateTime("SalaryMonth").Value; oRecognition.WfStatus = (EnumwfStatus)oReader.GetInt32("WfStatus").Value; oRecognition.RequestType = (EnumRequestType)oReader.GetInt32("RequestType").Value; oRecognition.IsCash = oReader.GetBoolean("IsCash").HasValue ? oReader.GetBoolean("IsCash").Value : false; oRecognition.Justification = oReader.GetString("Justification"); oRecognition.CreatedBy = oReader.GetInt32("CreatedBy", 0); oRecognition.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue ? oReader.GetDateTime("CreatedDate").Value : DateTime.MinValue; oRecognition.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oRecognition.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue ? oReader.GetDateTime("ModifiedDate").Value : (DateTime?)null; this.SetObjectState(oRecognition, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Recognition oRecognition = new Recognition(); MapObject(oRecognition, oReader); return oRecognition as T; } #endregion #region MapRecognitionDetail private void MapRecognitionDetailObject(RecognitionDetail oRecognitionDetail, DataReader oReader) { base.SetObjectID(oRecognitionDetail, (oReader.GetInt32("RecognitionDetailID").Value)); oRecognitionDetail.RecognitionID = oReader.GetInt32("RecognitionID", 0); oRecognitionDetail.EmployeeID = oReader.GetInt32("EmployeeID", 0); oRecognitionDetail.Amount = oReader.GetDouble("Amount").Value; oRecognitionDetail.SalaryMonth = oReader.GetDateTime("SalaryMonth").GetValueOrDefault(); oRecognitionDetail.PaidDate = oReader.GetDateTime("PaidDate").GetValueOrDefault(); oRecognitionDetail.RequestDate = oReader.GetDateTime("RequestDate").GetValueOrDefault(); this.SetObjectState(oRecognitionDetail, Ease.Core.ObjectState.Saved); } private RecognitionDetail CreateRecognitionDetailObject(DataReader oReader) { RecognitionDetail oRecognitionDetail = new RecognitionDetail(); MapRecognitionDetailObject(oRecognitionDetail, oReader); return oRecognitionDetail; } #endregion #region Recognition Service Methods public Recognition Get(int id) { Recognition oRecognition = new Recognition(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(RecognitionDA.Get(tc, id)); if (oreader.Read()) { oRecognition = 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 oRecognition; } public List Get() { List oRecognitions = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(RecognitionDA.Get(tc)); oRecognitions = 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 oRecognitions; } public int Save(Recognition oRecognition) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oRecognition.IsNew) { int id = tc.GenerateID("Recognitions", "RecognitionID"); base.SetObjectID(oRecognition, (id)); RecognitionDA.Insert(tc, oRecognition); } else { RecognitionDA.Update(tc, oRecognition); RecognitionDA.DeleteRecognitionDetail(tc, oRecognition.ID); } #region RecognitionDetail foreach (RecognitionDetail item in oRecognition.RecognitionDetails) { int id = tc.GenerateID("RecognitionDetails", "RecognitionDetailID"); base.SetObjectID(item, (id)); item.RecognitionID = oRecognition.ID; RecognitionDA.InsertRecognitionDetail(tc, item); } #endregion tc.End(); return oRecognition.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); RecognitionDA.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 UpdatePaidDate(List request, List Uncheckedrequest) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (RecognitionDetail item in request) { RecognitionDA.UpdatePaidDate(tc, item); } foreach (RecognitionDetail hRRequest in Uncheckedrequest) { hRRequest.PaidDate = DateTime.MinValue; RecognitionDA.UpdatePaidDate(tc, hRRequest); } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion #region RecognitionDetail Service Methods public List GetRecognitionDetails(int recognitionID) { List oRecognitionDetails = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(RecognitionDA.GetRecognitionDetails(tc, recognitionID)); while (dr.Read()) { RecognitionDetail oRecognitionDetail = new RecognitionDetail(); oRecognitionDetail = this.CreateRecognitionDetailObject(dr); oRecognitionDetails.Add(oRecognitionDetail); } 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 oRecognitionDetails; } public List GetRecognitionDetails(EnumwfStatus enumwfStatus, DateTime fromDate, DateTime toDate, bool p) { List oRecognitionDetails = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(RecognitionDA.GetRecognitionDetails(tc, enumwfStatus, fromDate, toDate, p)); while (dr.Read()) { RecognitionDetail oRecognitionDetail = new RecognitionDetail(); oRecognitionDetail = this.CreateRecognitionDetailObject(dr); oRecognitionDetails.Add(oRecognitionDetail); } 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 oRecognitionDetails; } //public List GetRecognitionDetails(EnumwfStatus enumwfStatus, DateTime fromDate, DateTime toDate, bool p) //{ // throw new NotImplementedException(); //} #endregion } }