EchoTex_Payroll/HRM.DA/Service/Basic/HrNotificationService.cs

172 lines
5.2 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using HRM.BO;
using HRM.BO.Basic;
using HRM.DA.DA.Basic;
namespace HRM.DA.Service.Basic
{
public class HrNotificationService : ServiceTemplate, IHrNotificationService
{
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.CreatedBy = oReader.GetInt32("CreatedBy", 0);
hrNotification.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
hrNotification.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
hrNotification.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(hrNotification, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(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;
}
public List<HrNotification> GetAll()
{
List<HrNotification> items = new List<HrNotification>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(HrNotificationDA.GetAll(tc));
items = this.CreateObjects<HrNotification>(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;
}
public HrNotification Get(int id)
{
HrNotification hrNotification = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(HrNotificationDA.Get(tc, id));
if (dr.Read())
{
hrNotification = this.CreateObject<HrNotification>(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 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.Insert(tc, hrNotification);
}
else
{
HrNotificationDA.Update(tc, hrNotification);
}
tc.End();
return hrNotification.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);
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
}
}
}
}