using DocumentFormat.OpenXml.Office2010.Excel; using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using HRM.BO; using HRM.BO.Basic; using HRM.DA.DA.Basic; using HRM.DA.DA.Tax; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HRM.DA.Service.Basic { public class HrNotificationService : ServiceTemplate, IHrNotificationService { public bool _isAll = true; public bool _isAllEmpWithDetails = false; private void MapObject(HrNotification hrNotification, DataReader oReader) { base.SetObjectID(hrNotification, oReader.GetInt32("hrNotificationId").Value); hrNotification.EntryDate = oReader.GetDateTime("EntryDate").Value; hrNotification.NotificationText = oReader.GetString("NotificationText"); hrNotification.NotificationTextDetail = oReader.GetString("NotificationTextDetail"); hrNotification.PublishDate = oReader.GetDateTime("PublishDate").Value; hrNotification.PublishEndDate = oReader.GetDateTime("PublishEndDate").GetValueOrDefault(); hrNotification.ShowAsNewDays = oReader.GetBoolean("ShowAsNewDays").GetValueOrDefault(); hrNotification.TotalNewDays = oReader.GetInt32("TotalNewDays").GetValueOrDefault(); hrNotification.NotificationType = (EnumHrNotificationType)oReader.GetInt32("NotificationType").Value; hrNotification.NotificationUrl = oReader.GetString("NotificationUrl", ""); hrNotification.CreatedBy = oReader.GetInt32("CreatedBy", 0); hrNotification.CreatedDate = oReader.GetDateTime("CreatedDate").Value; hrNotification.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); hrNotification.ModifiedDate = oReader.GetDateTime("ModifiedDate"); hrNotification.Status = (EnumStatus)oReader.GetInt32("Status", 0); hrNotification.IsSendToAll = oReader.GetBoolean("IsSendToAll", true); if (!_isAll) hrNotification.FileAsByteArray = oReader.GetLob("FileData"); hrNotification.OriginalFileName = oReader.GetString("OriginalFileName", ""); hrNotification.FileType = (EnumFileType)oReader.GetInt32("FileType", 15); this.SetObjectState(hrNotification, Ease.Core.ObjectState.Saved); } private void MapChildObject(HrNotificationEmployee hrNotification, DataReader oReader) { base.SetObjectID(hrNotification, oReader.GetInt32("HrNotificationEmployeeID").Value); hrNotification.HrNotificationId = oReader.GetInt32("HrNotificationId").Value; hrNotification.EmployeeId = oReader.GetInt32("EmployeeId", 0); hrNotification.NotificationType = (EnumHrNotificationType)oReader.GetInt32("NotificationType").Value; if (_isAllEmpWithDetails) { hrNotification.EmployeeNo = oReader.GetString("EmployeeNo", ""); hrNotification.Name = oReader.GetString("Name", ""); hrNotification.Department = oReader.GetString("Department", ""); hrNotification.Designation = oReader.GetString("Designation", ""); } this.SetObjectState(hrNotification, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { HrNotification item = new HrNotification(); MapObject(item, oReader); return item as T; } protected HrNotification CreateObject(DataReader oReader) { HrNotification item = new HrNotification(); MapObject(item, oReader); return item; } protected HrNotificationEmployee CreateChildObject(DataReader oReader) { HrNotificationEmployee item = new HrNotificationEmployee(); MapChildObject(item, oReader); return item; } protected HrNotificationEmployee CreateChildObjectWithDetails(DataReader oReader) { _isAllEmpWithDetails = true; HrNotificationEmployee item = new HrNotificationEmployee(); MapChildObject(item, oReader); _isAllEmpWithDetails = false; return item; } public List GetAll() { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(HrNotificationDA.GetAll(tc)); items = this.CreateObjects(dr); dr.Close(); if (items.Count > 0) { foreach (HrNotification item in items) { if (!item.IsSendToAll) { DataReader drs = new DataReader(HrNotificationDA.GetHrNotificationEmployees(tc, item.ID)); item.HrNotificationEmployees = this.CreateHREmployees(drs); 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 items; } public List GetAllNew() { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(HrNotificationDA.GetAllNew(tc)); items = this.CreateObjects(dr); dr.Close(); if (items.Count > 0) { foreach (HrNotification item in items) { if (!item.IsSendToAll) { DataReader drs = new DataReader(HrNotificationDA.GetHrNotificationEmployees(tc, item.ID)); item.HrNotificationEmployees = this.CreateHREmployees(drs); drs.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 items; } public List GetAllNew(int payrolltypeID) { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(HrNotificationDA.GetAllNew(tc, payrolltypeID)); items = this.CreateObjects(dr); dr.Close(); if (items.Count > 0) { foreach (HrNotification item in items) { if (!item.IsSendToAll) { DataReader drs = new DataReader(HrNotificationDA.GetHrNotificationEmployees(tc, item.ID)); item.HrNotificationEmployees = this.CreateHREmployees(drs); drs.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 items; } public List GetForEmployee(int payrolltypeID, int employeeID) { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(HrNotificationDA.GetForEmployee(tc, payrolltypeID, employeeID)); items = 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 items; } private List CreateHREmployees(DataReader oReader) { List oHRRequestDetails = new List(); HrNotificationEmployee oHRRequestDetail; while (oReader.Read()) { oHRRequestDetail = new HrNotificationEmployee(); oHRRequestDetail = CreateChildObject(oReader); oHRRequestDetails.Add(oHRRequestDetail); } return oHRRequestDetails; } private List CreateHREmployeeWithDetails(DataReader oReader) { List oHRRequestDetails = new List(); HrNotificationEmployee oHRRequestDetail; while (oReader.Read()) { oHRRequestDetail = new HrNotificationEmployee(); oHRRequestDetail = CreateChildObjectWithDetails(oReader); oHRRequestDetails.Add(oHRRequestDetail); } return oHRRequestDetails; } public HrNotification Get(int id) { HrNotification hrNotification = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); this._isAll = false; DataReader dr = new DataReader(HrNotificationDA.Get(tc, id)); if (dr.Read()) { hrNotification = this.CreateObject(dr); } dr.Close(); if (hrNotification != null && hrNotification.ID > 0) { if (!hrNotification.IsSendToAll) { DataReader drs = new DataReader(HrNotificationDA.GetHrNotificationEmployeeWithDetails(tc, hrNotification.ID)); hrNotification.HrNotificationEmployees = this.CreateHREmployeeWithDetails(drs); drs.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 hrNotification; } public int Save(HrNotification hrNotification) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (hrNotification.IsNew) { int id = tc.GenerateID("hrnotification", "hrNotificationId"); base.SetObjectID(hrNotification, id); HrNotificationDA.InsertWithAttachment(tc, hrNotification); if (!hrNotification.IsSendToAll) saveChild(tc, hrNotification); } else { HrNotificationDA.UpdateWithAttachment(tc, hrNotification); HrNotificationDA.DeleteChild(tc, hrNotification.ID); if (!hrNotification.IsSendToAll) saveChild(tc, hrNotification); } tc.End(); return hrNotification.ID; } catch (Exception e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); } } public void saveChild(TransactionContext tc, HrNotification hrNotification) { try { foreach (HrNotificationEmployee item in hrNotification.HrNotificationEmployees) { int childId = tc.GenerateID("HrNotificationEmployees", "HrNotificationEmployeeID"); base.SetObjectID(item, childId); item.HrNotificationId = hrNotification.ID; HrNotificationDA.Insert(tc, item); } } 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); HrNotificationDA.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 UploadHallOfFame(HallOfFame item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); HrNotificationDA.UploadHallOfFame(tc, item); tc.End(); } catch (Exception ex) { if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException("Failed to save file", ex); } } public DataTable GetHallOfFame() { TransactionContext tc = null; DataTable dt = new DataTable(); try { tc = TransactionContext.Begin(); dt = HrNotificationDA.GetHallOfFame(tc); tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException("Failed to Get Hall of Fame: " + ex.Message, ex); #endregion } return dt; } public void DeleteHallOfFame(int Id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); HrNotificationDA.DeleteHallOfFame(tc, Id); tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException("Could not delete, reason: " + ex.Message, ex); #endregion } } public void SaveLegalTracking(int legalTrackingID, string name, string shortDescription, string detailDescription, string nextAction, string nextActionDescription, DateTime fromDate, DateTime toDate, DateTime nextNotificationDate, int currentUserId) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); HrNotificationDA.SaveLegalTracking(tc, legalTrackingID, name, shortDescription, detailDescription, nextAction, nextActionDescription, fromDate, toDate, nextNotificationDate, currentUserId); tc.End(); } catch (Exception ex) { if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException("Failed to save", ex); } } public DataTable GetLegalTracking() { TransactionContext tc = null; DataTable dt = new DataTable(); try { tc = TransactionContext.Begin(); dt = HrNotificationDA.GetLegalTracking(tc); tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException("Failed to Get Hall of Fame: " + ex.Message, ex); #endregion } return dt; } public void DeleteLegalTracking(int Id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); HrNotificationDA.DeleteLegalTracking(tc, Id); tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException("Could not delete, reason: " + ex.Message, ex); #endregion } } } }