using Ease.Core; using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using HRM.BO; using System; using System.Collections.Generic; namespace HRM.DA { [Serializable] public class EmployeeNotificationService : ServiceTemplate, IEmployeeNotification { public EmployeeNotificationService() { } private void MapObject(EmployeeNotification item, DataReader reader) { base.SetObjectID(item, reader.GetInt32("ID").Value); item.EmployeeID = reader.GetInt32("EmployeeID").Value; item.Header = reader.GetString("Header", true, string.Empty); item.Description = reader.GetString("Description", true, string.Empty); item.Link = reader.GetString("Link", true, string.Empty); item.CreatedDate = reader.GetDateTime("CreatedDate").Value; item.CreatedBy = reader.GetInt32("CreatedBy").Value; if (reader.GetInt32("ReferenceID") != null) item.ReferenceID = reader.GetInt32("ReferenceID").Value; if (reader.GetInt32("IsRead") != null) item.IsRead = reader.GetInt32("IsRead").Value; if (reader.GetDateTime("ReadDate") != null) item.ReadDate = reader.GetDateTime("ReadDate").Value; if (reader.GetInt32("ReadBy") != null) item.ReadBy = reader.GetInt32("ReadBy").Value; this.SetObjectState(item, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader reader) { EmployeeNotification item = new EmployeeNotification(); MapObject(item, reader); return item as T; } public int Insert(EmployeeNotification item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (item.IsNew) this.SetObjectID(item, EmployeeNotificationDA.GetNewID(tc)); EmployeeNotificationDA.Insert(tc, item); tc.End(); } catch (Exception e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to insert Employee Notification: " + e.Message, e); } return item.ID; } public int Insert(TransactionContext tc, EmployeeNotification item) { try { if (item.IsNew) this.SetObjectID(item, EmployeeNotificationDA.GetNewID(tc)); EmployeeNotificationDA.Insert(tc, item); } catch (Exception e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to insert Employee Notification: " + e.Message, e); } return item.ID; } public void ReadUpdate(EmployeeNotification item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); EmployeeNotificationDA.ReadUpdate(tc, item); tc.End(); } catch (Exception e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to update Employee Notification read status: " + e.Message, e); } } public void MakeRead(int employeeID, List ids) { if (ids == null || ids.Count == 0) return; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); EmployeeNotificationDA.MakeRead(tc, employeeID, ids); tc.End(); } catch (Exception e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException( "Failed to update Employee Notification read status: " + e.Message, e); } } public List Get(int employeeID) { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader reader = new DataReader(EmployeeNotificationDA.Get(tc, employeeID)); items = this.CreateObjects(reader); reader.Close(); tc.End(); } catch (Exception e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to get Employee Notification: " + e.Message, e); } return items; } } }