CEL_Payroll/Payroll.Service/Basic/Service/ReligionService.cs

322 lines
9.8 KiB
C#
Raw Permalink Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Data;
using System.Linq;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
using System.Collections.Generic;
using Payroll.BO;
using Ease.CoreV35.Caching;
namespace Payroll.Service
{
#region Religion Service
[Serializable]
public class ReligionService : ServiceTemplate, IReligionService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(Religion));
#endregion
public ReligionService() { }
private void MapObject(Religion oReligion, DataReader oReader)
{
base.SetObjectID(oReligion, oReader.GetID("ReligionID"));
oReligion.Code = oReader.GetString("code");
oReligion.Name = oReader.GetString("name");
oReligion.Sequence = oReader.GetInt32("SequenceNO").Value;
oReligion.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oReligion.CreatedBy = oReader.GetID("CreatedBy");
oReligion.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oReligion.ModifiedBy = oReader.GetID("ModifiedBy");
oReligion.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oReligion, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
Religion oReligion = new Religion();
MapObject(oReligion, oReader);
return oReligion as T;
}
protected Religion CreateObject(DataReader oReader)
{
Religion oReligion = new Religion();
MapObject(oReligion, oReader);
return oReligion;
}
#region Service implementation
public string GetNextCode()
{
TransactionContext tc = null;
string _code = "";
try
{
tc = TransactionContext.Begin();
_code = GlobalFunctionService.GetMaxCode(tc, "religion", "codeautogenerate", "Religion", "Code");
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return _code;
}
public Religion Get(ID id)
{
Religion oReligion = new Religion();
#region Cache Header
oReligion = _cache["Get", id] as Religion;
if (oReligion != null)
return oReligion;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ReligionDA.Get(tc, id));
if (oreader.Read())
{
oReligion = this.CreateObject<Religion>(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(oReligion, "Get", id);
#endregion
return oReligion;
}
public Religion Get(string sCode)
{
Religion oReligion = new Religion();
#region Cache Header
oReligion = _cache["Get", sCode] as Religion;
if (oReligion != null)
return oReligion;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ReligionDA.Get(tc, sCode));
if (oreader.Read())
{
oReligion = this.CreateObject<Religion>(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(oReligion, "Get", sCode);
#endregion
return oReligion;
}
public ObjectsTemplate<Religion> Get()
{
#region Cache Header
ObjectsTemplate<Religion> religions = _cache["Get"] as ObjectsTemplate<Religion>;
if (religions != null)
return religions;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ReligionDA.Get(tc));
religions = this.CreateObjects<Religion>(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(religions, "Get");
#endregion
return religions;
}
public ObjectsTemplate<Religion> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<Religion> religions = _cache["Get"] as ObjectsTemplate<Religion>;
if (religions != null)
return religions;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ReligionDA.Get(tc, status));
religions = this.CreateObjects<Religion>(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(religions, "Get",status);
#endregion
return religions;
}
public ID Save(Religion oReligion)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oReligion.IsNew)
{
int id = tc.GenerateID("Religion", "ReligionID");
base.SetObjectID(oReligion, ID.FromInteger(id));
ReligionDA.Insert(tc, oReligion);
}
else
{
ReligionDA.Update(tc, oReligion);
}
tc.End();
return oReligion.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);
ReligionDA.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
//for Excel Upload
public static void SaveForUpload(TransactionContext tc, ObjectsTemplate<Religion> religions)
{
try
{
foreach (Religion oReligion in religions)
{
if (oReligion.IsNew)
{
int seqNo = tc.GenerateID("Religion", "SequenceNo");
oReligion.Sequence = seqNo;
bool isAutoGenerated = ConfigurationManager.GetBoolValue("religion", "codeautogenerate", EnumConfigurationType.Logic);
if (isAutoGenerated == true)
oReligion.Code = GlobalFunctionService.GetMaxCode(tc, "relition", "codeautogenerate", "Religion", "Code");
oReligion.Status = EnumStatus.Active;
oReligion.CreatedBy = User.CurrentUser.ID;
oReligion.CreatedDate = DateTime.Now;
ReligionDA.Insert(tc, oReligion);
}
else
{
oReligion.ModifiedBy = User.CurrentUser.ID;
oReligion.ModifiedDate = DateTime.Now;
ReligionDA.Update(tc, oReligion);
}
}
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
}
#endregion
}