CEL_Payroll/Payroll.Service/Loan/Service/LoanEmployeeDocService.cs

210 lines
6.6 KiB
C#
Raw Permalink Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
using Payroll.BO;
using Ease.CoreV35.Caching;
namespace Payroll.Service
{
#region LoanEmployeeDoc Service
[Serializable]
public class LoanEmployeeDocService : ServiceTemplate, ILoanEmployeeDocService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(LoanEmployeeDoc));
#endregion
public LoanEmployeeDocService() { }
#region MapObject For LoanEmployeeDoc
private void MapObject(LoanEmployeeDoc oLoanEmployeeDoc, DataReader oReader)
{
base.SetObjectID(oLoanEmployeeDoc, oReader.GetID("LoanEmpDocID"));
oLoanEmployeeDoc.HRDocID = oReader.GetID("HRDocID");
oLoanEmployeeDoc.LoanIssueID = oReader.GetID("LoanIssueID");
oLoanEmployeeDoc.EmployeeID = oReader.GetID("employeeID");
oLoanEmployeeDoc.HRID = oReader.GetID("HRID");
oLoanEmployeeDoc.HRReceiveDate = oReader.GetDateTime("HRReceivedDate").Value;
oLoanEmployeeDoc.FileNo = oReader.GetString("FileNo");
oLoanEmployeeDoc.SafeNo = oReader.GetString("SafeNo");
oLoanEmployeeDoc.HRRemarks = oReader.GetString("HRRemarks");
oLoanEmployeeDoc.EmpReceiveDate = oReader.GetDateTime("EmpReceiveDate").Value;
oLoanEmployeeDoc.EmpReceiveRemarks = oReader.GetString("EmpReceiveRemarks");
oLoanEmployeeDoc.CreatedBy = oReader.GetID("CreatedBy");
oLoanEmployeeDoc.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oLoanEmployeeDoc.ModifiedBy = oReader.GetID("ModifiedBy");
oLoanEmployeeDoc.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oLoanEmployeeDoc, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
LoanEmployeeDoc oLoanEmployeeDoc = new LoanEmployeeDoc();
MapObject(oLoanEmployeeDoc, oReader);
return oLoanEmployeeDoc as T;
}
protected LoanEmployeeDoc CreateObject(DataReader oReader)
{
LoanEmployeeDoc oLoanEmployeeDoc = new LoanEmployeeDoc();
MapObject(oLoanEmployeeDoc, oReader);
return oLoanEmployeeDoc;
}
#endregion
#region Service Implementation of LoanEmployeeDoc
public LoanEmployeeDoc Get(ID id)
{
LoanEmployeeDoc oLoanEmpDoc = new LoanEmployeeDoc();
#region Cache Header
oLoanEmpDoc = _cache["Get", id] as LoanEmployeeDoc;
if (oLoanEmpDoc != null)
return oLoanEmpDoc;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(LoanEmployeeDocDA.Get(tc, id));
if (oreader.Read())
{
oLoanEmpDoc = this.CreateObject<LoanEmployeeDoc>(oreader);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
#region Cache Footer
_cache.Add(oLoanEmpDoc, "Get", id);
#endregion
return oLoanEmpDoc;
}
public ObjectsTemplate<LoanEmployeeDoc> GetbyIssueId(ID issueId)
{
#region Cache Header
ObjectsTemplate<LoanEmployeeDoc> LoanEmpDocs = _cache["Get"] as ObjectsTemplate<LoanEmployeeDoc>;
if (LoanEmpDocs != null)
return LoanEmpDocs;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanEmployeeDocDA.GetbyIssueId(tc, issueId));
LoanEmpDocs = this.CreateObjects<LoanEmployeeDoc>(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
}
#region Cache Footer
_cache.Add(LoanEmpDocs, "Get");
#endregion
return LoanEmpDocs;
}
public ID Save(TransactionContext tc, LoanEmployeeDoc oLoanEmpDoc)
{
try
{
if (oLoanEmpDoc.IsNew)
{
int id = tc.GenerateID("LoanEmpDoc", "LoanEmpDocID");
base.SetObjectID(oLoanEmpDoc, ID.FromInteger(id));
LoanEmployeeDocDA.Insert(tc, oLoanEmpDoc);
}
else
{
LoanEmployeeDocDA.Update(tc, oLoanEmpDoc);
}
return oLoanEmpDoc.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void DeletebyIssueid(TransactionContext tc, ID id)
{
try
{
LoanEmployeeDocDA.DeletebyIssueid(tc, 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(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
LoanEmployeeDocDA.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
}
}
#endregion
}
#endregion
}