CEL_Payroll/Payroll.Service/Users/Service/PasswordHistoryService.cs

140 lines
4.0 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Data;
using System.Linq;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
using System.Collections.Generic;
using Payroll.BO;
using Ease.CoreV35.Caching;
namespace Payroll.Service
{
public class PasswordHistoryService : ServiceTemplate, IPasswordHistoryService
{
private void MapObject(PasswordHistory oHistory, DataReader oReader)
{
base.SetObjectID(oHistory, ID.FromInteger(oReader.GetInt32("PasswordHistoryID").Value));
oHistory.UserID = ID.FromInteger(oReader.GetInt32("UserID").Value);
oHistory.UserPassword = oReader.GetString("UserPassword");
oHistory.CreatedDate = oReader.GetDateTime("CreationDate").Value;
this.SetObjectState(oHistory, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
PasswordHistory oHistory = new PasswordHistory();
MapObject(oHistory, oReader);
return oHistory as T;
}
public ID Save(PasswordHistory oHistory)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
int id = tc.GenerateID("PasswordHistory", "PasswordHistoryID");
base.SetObjectID(oHistory, ID.FromInteger(id));
PasswordHistoryDA.Insert(tc, oHistory);
tc.End();
return oHistory.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public ObjectsTemplate<PasswordHistory> Get()
{
ObjectsTemplate<PasswordHistory> histories = new ObjectsTemplate<PasswordHistory>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(PasswordHistoryDA.Get(tc));
histories = this.CreateObjects<PasswordHistory>(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 histories;
}
public ObjectsTemplate<PasswordHistory> Get(ID nUserID)
{
ObjectsTemplate<PasswordHistory> histories = new ObjectsTemplate<PasswordHistory>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(PasswordHistoryDA.Get(tc, nUserID));
histories = this.CreateObjects<PasswordHistory>(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 histories;
}
public void Delete(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
PasswordHistoryDA.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
}
}
}
}