EchoTex_Payroll/HRM.DA/Service/HRBasic/ThanaService.cs

270 lines
6.8 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 HRM.BO;
using System.Collections.Generic;
using Ease.Core.Utility;
namespace HRM.DA
{
#region class Thana Service
public class ThanaService : ServiceTemplate, IThanaService
{
#region constructor
public ThanaService()
{
}
#endregion
#region object
private void MapObject(Thana oThana, DataReader oReader)
{
base.SetObjectID(oThana, oReader.GetInt32("THANAID").Value);
oThana.Code = oReader.GetString("CODE");
oThana.Name = oReader.GetString("NAME");
oThana.DistrictID = oReader.GetInt32("DISTRICTID", 0);
oThana.Sequence = oReader.GetInt32("SequenceNo").Value;
oThana.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oThana.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oThana.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oThana.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oThana.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oThana, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
Thana oThana = new Thana();
MapObject(oThana, oReader);
return oThana as T;
}
#endregion
#region Service implementation
public Thana Get(int id)
{
Thana oThana = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ThanaDA.Get(tc, id));
if (oreader.Read())
{
oThana = this.CreateObject<Thana>(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 oThana;
}
public Thana Get(string sCode)
{
Thana oThana = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ThanaDA.Get(tc, sCode));
if (oreader.Read())
{
oThana = this.CreateObject<Thana>(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 oThana;
}
public List<Thana> Get()
{
List<Thana> thanas = new List<Thana>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ThanaDA.Get(tc));
thanas = this.CreateObjects<Thana>(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 thanas;
}
public List<Thana> Get(EnumStatus status)
{
List<Thana> thanas = new List<Thana>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ThanaDA.Get(tc, status));
thanas = this.CreateObjects<Thana>(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 thanas;
}
public List<Thana> GetByDistID(int nDistID)
{
List<Thana> thanas = new List<Thana>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ThanaDA.GetByDistID(tc, nDistID));
thanas = this.CreateObjects<Thana>(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 thanas;
}
public int Save(Thana oThana)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oThana.IsNew)
{
int id = tc.GenerateID("THANA", "THANAID");
base.SetObjectID(oThana, id);
if (oThana.Code == "")
oThana.Code = oThana.ID.ToString();
ThanaDA.Insert(tc, oThana);
}
else
{
ThanaDA.Update(tc, oThana);
}
tc.End();
return oThana.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);
ThanaDA.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
}