CEL_Payroll/Payroll.Service/Attendence/Service/EmpFieldTrackService.cs
2024-09-17 14:30:13 +06:00

168 lines
5.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35.DataAccess;
using Ease.CoreV35.Caching;
using Ease.CoreV35.Model;
using Payroll.BO;
namespace Payroll.Service
{
class EmpFieldTrackService : ServiceTemplate, IEmpFieldTrackService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(EmpFieldTrack));
#endregion
protected override T CreateObject<T>(DataReader dr)
{
EmpFieldTrack attendanceTrack = new EmpFieldTrack();
MapObject(attendanceTrack, dr);
return attendanceTrack as T;
}
private void MapObject(EmpFieldTrack oEmpFieldTrack, DataReader oReader)
{
base.SetObjectID(oEmpFieldTrack, oReader.GetID("EmpFieldTrackID"));
oEmpFieldTrack.EmployeeID = oReader.GetID("EmployeeID");
oEmpFieldTrack.IMENumber = oReader.GetString("IMENO");
oEmpFieldTrack.NearLocation = oReader.GetString("NearLocation");
oEmpFieldTrack.Client = oReader.GetString("Client");
oEmpFieldTrack.Remarks = oReader.GetString("Remarks");
oEmpFieldTrack.Zipcode = oReader.GetString("Zipcode");
oEmpFieldTrack.Latitude = oReader.GetDecimal("Latitude").Value;
oEmpFieldTrack.Longitude = oReader.GetDecimal("Longitude").Value;
oEmpFieldTrack.TranDateTime = oReader.GetDateTime("TranDateTime").HasValue ? oReader.GetDateTime("TranDateTime").Value : DateTime.MinValue;
this.SetObjectState(oEmpFieldTrack, Ease.CoreV35.ObjectState.Saved);
}
#region IUserLocationService Members
public ObjectsTemplate<EmpFieldTrack> Get()
{
TransactionContext tc = null;
ObjectsTemplate<EmpFieldTrack> listEmpFieldTrack = new ObjectsTemplate<EmpFieldTrack>(); ;
#region Cache Header
listEmpFieldTrack = _cache["Get"] as ObjectsTemplate<EmpFieldTrack>;
if (listEmpFieldTrack != null)
return listEmpFieldTrack;
#endregion
try
{
tc = TransactionContext.Begin(true);
DataReader oreader = new DataReader(EmpFieldTrackDA.Get(tc));
listEmpFieldTrack = this.CreateObjects<EmpFieldTrack>(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(listEmpFieldTrack, "Get");
#endregion
return listEmpFieldTrack;
}
public EmpFieldTrack Get(ID nID)
{
TransactionContext tc = null;
EmpFieldTrack empFieldTrack = new EmpFieldTrack();
#region Cache Header
empFieldTrack = _cache["Get", nID] as EmpFieldTrack;
if (empFieldTrack != null)
return empFieldTrack;
#endregion
try
{
tc = TransactionContext.Begin(true);
DataReader oreader = new DataReader(EmpFieldTrackDA.Get(tc, nID));
if (oreader.Read())
{
empFieldTrack = this.CreateObject<EmpFieldTrack>(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(empFieldTrack, "Get", nID);
#endregion
return empFieldTrack;
}
public ID Save(EmpFieldTrack obj)
{
TransactionContext tc = null;
ID oId = null;
try
{
tc = TransactionContext.Begin(true);
if (obj.IsNew)
{
int id = tc.GenerateID("EMPFIELDTRACK", "EmpFieldTrackID");
base.SetObjectID(obj, ID.FromInteger(id));
oId = EmpFieldTrackDA.Insert(tc, obj);
}
else
{
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oId;
}
public void Delete(ID obj)
{
TransactionContext tc = null;
//ID oId = null;
try
{
tc = TransactionContext.Begin(true);
EmpFieldTrackDA.Delete(tc, obj);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
}
}