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

261 lines
8.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
using Payroll.BO;
using Ease.CoreV35.Caching;
namespace Payroll.Service
{
[Serializable]
public class SurveyOrganizationService : ServiceTemplate, ISurveyOrganizationService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(SurveyOrganization));
#endregion
public SurveyOrganizationService() { }
private void MapObject(SurveyOrganization oSurveyOrganization, DataReader oReader)
{
//base.SetObjectID(oSurveyOrganization, oReader.GetID("SurveyOrganizationID"));
oSurveyOrganization.SurveyID = oReader.GetID("SurveyID");
oSurveyOrganization.GradeID = oReader.GetID("GradeID");
oSurveyOrganization.CompanyID = oReader.GetID("CompanyID");
oSurveyOrganization.DepartmentID = oReader.GetID("DepartmentID");
oSurveyOrganization.LocationID = oReader.GetID("LocationID");
this.SetObjectState(oSurveyOrganization, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
SurveyOrganization oSurveyOrganization = new SurveyOrganization();
MapObject(oSurveyOrganization, oReader);
return oSurveyOrganization as T;
}
protected SurveyOrganization CreateObject(DataReader oReader)
{
SurveyOrganization oSurveyOrganization = new SurveyOrganization();
MapObject(oSurveyOrganization, oReader);
return oSurveyOrganization;
}
#region Service implementation
public ObjectsTemplate<SurveyOrganization> GetSurveyOrganization(ID surveyId)
{
#region Cache Header
ObjectsTemplate<SurveyOrganization> oSurveyOrganizations = _cache["GetSurveyOrganization", surveyId] as ObjectsTemplate<SurveyOrganization>;
if (oSurveyOrganizations != null)
return oSurveyOrganizations;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SurveyOrganizationDA.GetSurveyOrganization(tc, surveyId.Integer));
oSurveyOrganizations = this.CreateObjects<SurveyOrganization>(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(oSurveyOrganizations, "GetSurveyOrganization", surveyId);
#endregion
return oSurveyOrganizations;
}
public SurveyOrganization Get(ID id)
{
SurveyOrganization oSurveyOrganization = new SurveyOrganization();
#region Cache Header
oSurveyOrganization = _cache["Get", id] as SurveyOrganization;
if (oSurveyOrganization != null)
return oSurveyOrganization;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(SurveyOrganizationDA.Get(tc, id));
if (oreader.Read())
{
oSurveyOrganization = this.CreateObject<SurveyOrganization>(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(oSurveyOrganization, "Get", id);
#endregion
return oSurveyOrganization;
}
public ObjectsTemplate<SurveyOrganization> Get()
{
#region Cache Header
ObjectsTemplate<SurveyOrganization> SurveyOrganizations = _cache["Get"] as ObjectsTemplate<SurveyOrganization>;
if (SurveyOrganizations != null)
return SurveyOrganizations;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SurveyOrganizationDA.Get(tc));
SurveyOrganizations = this.CreateObjects<SurveyOrganization>(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(SurveyOrganizations, "Get");
#endregion
return SurveyOrganizations;
}
public ObjectsTemplate<SurveyOrganization> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<SurveyOrganization> SurveyOrganizations = _cache["Get",status] as ObjectsTemplate<SurveyOrganization>;
if (SurveyOrganizations != null)
return SurveyOrganizations;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SurveyOrganizationDA.Get(tc, status));
SurveyOrganizations = this.CreateObjects<SurveyOrganization>(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(SurveyOrganizations, "Get",status);
#endregion
return SurveyOrganizations;
}
public ID Save(SurveyOrganization oSurveyOrganization)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oSurveyOrganization.IsNew)
{
//int id = tc.GenerateID("SurveyOrganization", "SurveyOrganizationID");
//base.SetObjectID(oSurveyOrganization, ID.FromInteger(id));
SurveyOrganizationDA.Insert(tc, oSurveyOrganization);
}
else
{
SurveyOrganizationDA.Update(tc, oSurveyOrganization);
}
tc.End();
return oSurveyOrganization.SurveyID;
}
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);
SurveyOrganizationDA.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
}
}