EchoTex_Payroll/HRM.DA/Service/Basic/RemainderService.cs
2024-10-14 10:01:49 +06:00

132 lines
3.8 KiB
C#

using System;
using System.Data;
using System.Linq;
using System.Collections.Generic;
using HRM.BO;
using HRM.DA;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core.Utility;
using Ease.Core;
namespace HRM.DA
{
public class ReminderService : ServiceTemplate, IReminderService
{
public ReminderService()
{
}
private void MapObject(Reminder oReminder, DataReader oReader)
{
base.SetObjectID(oReminder, oReader.GetInt32("ReminderId").Value);
oReminder.EmployeeId = oReader.GetInt32("EmployeeId", 0);
oReminder.Description = oReader.GetString("Description", string.Empty);
oReminder.ReminderStatus = (EnumReminderStatus)oReader.GetInt32("ReminderStatus").Value;
oReminder.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oReminder.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oReminder.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oReminder.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oReminder.Time = oReader.GetDateTime("Time").Value;
this.SetObjectState(oReminder, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
Reminder oReminder = new Reminder();
MapObject(oReminder, oReader);
return oReminder as T;
}
protected Reminder CreateObject(DataReader oReader)
{
Reminder oReminder = new Reminder();
MapObject(oReminder, oReader);
return oReminder;
}
public List<Reminder> Get(int EmployeeId)
{
List<Reminder> Remainders = new List<Reminder>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(RemainderDA.Get(tc, EmployeeId));
Remainders = this.CreateObjects<Reminder>(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 Remainders;
}
public int Save(Reminder item)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (item.IsNew)
{
int id = tc.GenerateID("Reminders", "ReminderId");
base.SetObjectID(item, id);
RemainderDA.Insert(tc, item);
}
else
{
RemainderDA.Update(tc, item);
}
tc.End();
return item.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);
RemainderDA.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
}
}
}
}