EchoTex_Payroll/HRM.DA/Service/Common/PhotopathService.cs

175 lines
5.1 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using System;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core.Utility;
using System.Collections.Generic;
using HRM.BO;
using System.Data;
namespace HRM.DA
{
#region PhotoPath Service
public class PhotoPathService : ServiceTemplate, IPhotoPathService
{
public PhotoPathService()
{
}
private void MapObject(PhotoPath oPhotoPath, DataReader oReader)
{
base.SetObjectID(oPhotoPath, (oReader.GetInt32("PathID").Value));
oPhotoPath.EmployeePhoto = oReader.GetString("EmployeePhoto");
oPhotoPath.EmployeeSignature = oReader.GetString("EmployeeSignature");
oPhotoPath.NomineePhoto = oReader.GetString("NomineePhoto");
oPhotoPath.NomineeSignature = oReader.GetString("NomineeSignature");
oPhotoPath.HospitalizationPhoto = oReader.GetString("HospitalizationPhoto");
oPhotoPath.LetterTempPath = oReader.GetString("LetterTempPath");
oPhotoPath.TrainingOutlinePath = oReader.GetString("TrainingOutlinePath");
oPhotoPath.ERRSFilePath = oReader.GetString("ERRSFilePath");
oPhotoPath.AttendanceSourceFilePath = oReader.GetString("AttendanceSourceFilePath");
oPhotoPath.AttendanceBackUpFilePath = oReader.GetString("AttendanceBackUpFilePath");
oPhotoPath.BadliAttendanceSourceFilePath = oReader.GetString("BadliAttnSourceFilePath");
oPhotoPath.BadliAttendanceBackUpFilePath = oReader.GetString("BadliAttnBackUpFilePath");
this.SetObjectState(oPhotoPath, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
PhotoPath oPhotoPath = new PhotoPath();
MapObject(oPhotoPath, oReader);
return oPhotoPath as T;
}
protected PhotoPath CreateObject(DataReader oReader)
{
PhotoPath oPhotoPath = new PhotoPath();
MapObject(oPhotoPath, oReader);
return oPhotoPath;
}
#region Service implementation
public PhotoPath Get(int id)
{
PhotoPath oPhotoPath = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PhotoPathDA.Get(tc, id));
if (oreader.Read())
{
oPhotoPath = this.CreateObject<PhotoPath>(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
}
return oPhotoPath;
}
public List<PhotoPath> Get()
{
List<PhotoPath> PhotoPaths = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(PhotoPathDA.Get(tc));
PhotoPaths = this.CreateObjects<PhotoPath>(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 PhotoPaths;
}
public int Save(PhotoPath oPhotoPath)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oPhotoPath.IsNew)
{
int id = tc.GenerateID("PhotoPath", "PathID");
base.SetObjectID(oPhotoPath, (id));
PhotoPathDA.Insert(tc, oPhotoPath);
}
else
{
PhotoPathDA.Update(tc, oPhotoPath);
}
tc.End();
return oPhotoPath.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);
PhotoPathDA.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
}