using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using HRM.BO; using HRM.BO.Configuration; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using static iTextSharp.text.pdf.AcroFields; namespace HRM.DA { public class LongServiceAwardService : ServiceTemplate, ILongServiceAwardService { #region Constructor public LongServiceAwardService() { } #endregion #region LongServiceAwardMaster MapObject private void MapObject(BO.LongServiceAwardMaster oLongServiceAwardMaster, DataReader oReader) { base.SetObjectID(oLongServiceAwardMaster, oReader.GetInt32("LongServiceAwardID").Value); oLongServiceAwardMaster.AwardName = oReader.GetString("AwardName") == null ? string.Empty : oReader.GetString("AwardName"); oLongServiceAwardMaster.AwardDescription = oReader.GetString("AwardDescription") == null ? string.Empty : oReader.GetString("AwardDescription"); oLongServiceAwardMaster.AwardType = (EnumAwardType)oReader.GetInt32("AwardType").Value; oLongServiceAwardMaster.AwardStatus = (EnumAwardStatus)oReader.GetInt32("AwardStatus").Value; oLongServiceAwardMaster.AwardDate = oReader.GetDateTime("AwardDate").Value; oLongServiceAwardMaster.CreatedBy = oReader.GetString("CreatedBy") == null ? 0 : oReader.GetInt32("CreatedBy").Value; oLongServiceAwardMaster.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oLongServiceAwardMaster.ModifiedBy = oReader.GetString("ModifiedBy") == null ? 0 : oReader.GetInt32("ModifiedBy").Value; oLongServiceAwardMaster.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oLongServiceAwardMaster, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { BO.LongServiceAwardMaster oLongServiceAwardMaster = new BO.LongServiceAwardMaster(); MapObject(oLongServiceAwardMaster, oReader); return oLongServiceAwardMaster as T; } protected BO.LongServiceAwardMaster CreateObject(DataReader oReader) { BO.LongServiceAwardMaster oLongServiceAwardMaster = new BO.LongServiceAwardMaster(); MapObject(oLongServiceAwardMaster, oReader); return oLongServiceAwardMaster; } #endregion #region LongServiceAwardChild MapObject private void MapLongServiceAwardChildObject(LongServiceAwardChild oLongServiceAwardChild, DataReader oReader) { base.SetObjectID(oLongServiceAwardChild, oReader.GetInt32("LongServiceAwardChildID").Value); oLongServiceAwardChild.LongServiceAwardID = oReader.GetInt32("LongServiceAwardID").Value; oLongServiceAwardChild.EmployeeID = oReader.GetInt32("EmployeeID").Value; oLongServiceAwardChild.Amount = oReader.GetDouble("Amount").Value; oLongServiceAwardChild.Gift = oReader.GetString("Gift"); oLongServiceAwardChild.IsLMMailDone = oReader.GetBoolean("IsLMMailDone")==null? false: true; oLongServiceAwardChild.LineManagerID = oReader.GetInt32("LineManagerID").Value; oLongServiceAwardChild.LMComment = oReader.GetString("LMComment"); oLongServiceAwardChild.LMCommentDate = oReader.GetDateTime("LMCommentDate").Value; oLongServiceAwardChild.CreatedBy = oReader.GetString("CreatedBy") == null ? 0 : oReader.GetInt32("CreatedBy").Value; oLongServiceAwardChild.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oLongServiceAwardChild.ModifiedBy = oReader.GetString("ModifiedBy") == null ? 0 : oReader.GetInt32("ModifiedBy").Value; oLongServiceAwardChild.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oLongServiceAwardChild, Ease.Core.ObjectState.Saved); } private LongServiceAwardChild CreateLongServiceAwardChildObject(DataReader oReader) { LongServiceAwardChild oLongServiceAwardChild = new LongServiceAwardChild(); MapLongServiceAwardChildObject(oLongServiceAwardChild, oReader); return oLongServiceAwardChild; } protected List CreateLongServiceAwardChildObjects(DataReader oReader) { List oLongServiceAwardChild = new List(); while (oReader.Read()) { LongServiceAwardChild item = CreateLongServiceAwardChildObject(oReader); oLongServiceAwardChild.Add(item); } return oLongServiceAwardChild; } #endregion #region Function Implementation public List Get() { List oLongServiceAwardMasters = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LongServiceAwardDA.Get(tc)); oLongServiceAwardMasters = this.CreateObjects(dr); dr.Close(); if(oLongServiceAwardMasters.Count>0) { foreach(LongServiceAwardMaster item in oLongServiceAwardMasters) { item.Details = this.GetChildById(tc, item.ID); } } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oLongServiceAwardMasters; } public List GetChildById(TransactionContext tc ,int ID) { List oLongServiceAwardMasters = new List(); try { DataReader dr = new DataReader(LongServiceAwardDA.GetChildById(tc, ID)); oLongServiceAwardMasters = this.CreateLongServiceAwardChildObjects(dr); dr.Close(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oLongServiceAwardMasters; } public List GetByDateRange(DateTime fromDate, DateTime toDate) { List oLongServiceAwardMasters = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LongServiceAwardDA.GetByDateRange(tc, fromDate, toDate)); oLongServiceAwardMasters = this.CreateObjects(dr); dr.Close(); if (oLongServiceAwardMasters.Count > 0) { foreach (LongServiceAwardMaster item in oLongServiceAwardMasters) { item.Details = this.GetChildById(tc, item.ID); } } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oLongServiceAwardMasters; } public void SaveLongServiceAward(LongServiceAwardMaster oLongServiceAwardMaster) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if(oLongServiceAwardMaster.IsNew) { int id = tc.GenerateID("LongServiceAwardMaster", "LongServiceAwardID"); base.SetObjectID(oLongServiceAwardMaster, id); LongServiceAwardDA.Insert(tc, oLongServiceAwardMaster); foreach(LongServiceAwardChild item in oLongServiceAwardMaster.Details) { item.LongServiceAwardID = oLongServiceAwardMaster.ID; int childID = tc.GenerateID("LongServiceAwardChild", "LongServiceAwardChildID"); base.SetObjectID(item, childID); LongServiceAwardDA.Insert(tc, item); } } else { LongServiceAwardDA.Update(tc, oLongServiceAwardMaster); LongServiceAwardDA.Delete(tc, oLongServiceAwardMaster.ID); foreach (LongServiceAwardChild item in oLongServiceAwardMaster.Details) { int id = tc.GenerateID("LongServiceAwardChild", "LongServiceAwardChildID"); base.SetObjectID(item, id); LongServiceAwardDA.Insert(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 DeleteLongServiceAward(LongServiceAwardMaster item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); LongServiceAwardDA.Delete(tc, item.ID); LongServiceAwardDA.Delete(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 DataTable GetEmployeeDataforLongServiceAward(int item, DateTime date) { DataTable dt = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); dt = LongServiceAwardDA.GetEmployeeDataforLongServiceAward(tc, item, date); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return dt; } public void SendMail(LongServiceAwardMaster item, MailSender oMailSender, EmailSettings emailSettings) { Employee employee = null; try { foreach (LongServiceAwardChild citem in item.Details) { if (citem.LineManagerID == 0) continue; employee = new EmployeeService().Get(citem.LineManagerID); if (employee != null && employee.EmailAddress !="") { oMailSender.To = ""; oMailSender.AddTo(employee.EmailAddress); oMailSender.Subject = "Long Service Award Verification"; if (item.AwardStatus == EnumAwardStatus.SentToLMForReview) { oMailSender.Body = "The employee under you is awarded for completion" + "selective timeline. Please check. If you find eny irregularities let the HR know" + "Thanks"; } else if (item.AwardStatus == EnumAwardStatus.ReviewReceived) { oMailSender.Body = "The employee under you is awarded for completion" + "selective timeline. Please check. If you find eny irregularities let the HR know" + "Thanks"; } else if (item.AwardStatus == EnumAwardStatus.PaymentDone) { oMailSender.Body = "The employee under you have done the payemnt for the award" + ". Please check. If you find eny irregularities let the HR know" + "Thanks"; } oMailSender.SendMail(emailSettings); } } } catch (Exception) { throw; } } #endregion } }