CEL_Payroll/Payroll.Service/Survey/Service/SurveyEmployeeService.cs

166 lines
5.2 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Payroll.BO;
using System.Data;
using Ease.CoreV35.Model;
using System.Data.SqlClient;
using Ease.CoreV35.DataAccess;
using Ease.CoreV35.DataAccess.SQL;
using Ease.CoreV35.Caching;
namespace Payroll.Service
{
[Serializable]
public class SurveyEmployeeService : ServiceTemplate, ISurveyEmployeeService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(SurveyEmployee));
#endregion
public SurveyEmployeeService() { }
private void MapObject(SurveyEmployee oSurveyEmployee, DataReader oReader)
{
// base.SetObjectID(oSurveyEmployee, oReader.GetID("SurveyEmployeeID"));
oSurveyEmployee.SurveyID = oReader.GetID("SurveyID");
oSurveyEmployee.EmployeeID = oReader.GetInt32("EmployeeID").GetValueOrDefault();
this.SetObjectState(oSurveyEmployee, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
SurveyEmployee oSurveyEmployee = new SurveyEmployee();
MapObject(oSurveyEmployee, oReader);
return oSurveyEmployee as T;
}
#region Service implementation
public ObjectsTemplate<SurveyEmployee> GetSurveyEmployee(ID surveyId)
{
#region Cache Header
ObjectsTemplate<SurveyEmployee> oSurveyEmployees = _cache["GetSurveyEmployee",surveyId] as ObjectsTemplate<SurveyEmployee>;
if (oSurveyEmployees != null)
return oSurveyEmployees;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SurveyEmployeeDA.GetSurveyEmployee(tc,surveyId.Integer));
oSurveyEmployees = this.CreateObjects<SurveyEmployee>(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(oSurveyEmployees, "GetSurveyEmployee", surveyId);
#endregion
return oSurveyEmployees;
}
public ObjectsTemplate<SurveyEmployee> GetSurveyEmployee()
{
#region Cache Header
ObjectsTemplate<SurveyEmployee> oSurveyEmployees = _cache["GetSurveyEmployee"] as ObjectsTemplate<SurveyEmployee>;
if (oSurveyEmployees != null)
return oSurveyEmployees;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SurveyEmployeeDA.GetSurveyEmployee(tc));
oSurveyEmployees = this.CreateObjects<SurveyEmployee>(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(oSurveyEmployees, "GetSurveyEmployee");
#endregion
return oSurveyEmployees;
}
public ID Save(SurveyEmployee oSurveyEmployee)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oSurveyEmployee.IsNew)
{
//int id = tc.GenerateID("SurveyEmployee", "SurveyEmployeeID");
//base.SetObjectID(oSurveyEmployee, ID.FromInteger(id));
SurveyEmployeeDA.Insert(tc, oSurveyEmployee);
}
else
{
SurveyEmployeeDA.Update(tc, oSurveyEmployee);
}
tc.End();
return oSurveyEmployee.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);
SurveyEmployeeDA.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
}
}