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

254 lines
7.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 HRM.BO;
using Ease.Core.Utility;
using System.Collections.Generic;
namespace HRM.DA
{
public class CountryService : ServiceTemplate, ICountryService
{
#region constructor
public CountryService()
{
}
#endregion
#region Object
private void MapObject(Country oCountry, DataReader oReader)
{
//#####
base.SetObjectID(oCountry, oReader.GetInt32("COUNTRYID").Value);
oCountry.Code = oReader.GetString("CODE");
oCountry.Name = oReader.GetString("NAME");
//oCountry.Sequence = oReader.GetInt32("SequenceNo").Value;
//oCountry.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oCountry.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oCountry.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oCountry.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oCountry.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oCountry, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
Country oCountry = new Country();
MapObject(oCountry, oReader);
return oCountry as T;
}
#endregion
#region Service implementation
public Country Get(int id)
{
Country oCountry = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(CountryDA.Get(tc, id));
if (oreader.Read())
{
oCountry = this.CreateObject<Country>(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 oCountry;
}
public Country Get(string sCode)
{
Country oCountry = null;
//TransactionContext tc = null;
//try
//{
// tc = TransactionContext.Begin();
// DataReader oreader = new DataReader(CountryService.Get(tc, sCode));
// if (oreader.Read())
// {
// oCountry = this.CreateObject<Country>(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 oCountry;
}
public List<Country> Get()
{
List<Country> countries = new List<Country>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
// DataReader dr = new DataReader(CountryService.Get(tc));
DataReader dr = new DataReader(CountryDA.Get(tc));
countries = this.CreateObjects<Country>(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 countries;
}
public List<Country> Get(EnumStatus status, int payrolltypeid)
{
List<Country> countries = new List<Country>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(CountryDA.Get(tc, status));
countries = this.CreateObjects<Country>(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 countries;
}
public List<Country> Get(EnumStatus status)
{
List<Country> countries = new List<Country>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(CountryDA.Get(tc, status));
countries = this.CreateObjects<Country>(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 countries;
}
public int Save(Country oCountry)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oCountry.IsNew)
{
int id = tc.GenerateID("COUNTRY", "COUNTRYID");
base.SetObjectID(oCountry, id);
if (oCountry.Code == "")
oCountry.Code = oCountry.ID.ToString();
CountryDA.Insert(tc, oCountry);
}
else
{
CountryDA.Update(tc, oCountry);
}
tc.End();
return oCountry.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);
// CountryService.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
}
}