CEL_Payroll/Payroll.Service/Survey/Service/SurveyWeightDefinitionService.cs

156 lines
5.4 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 SurveyWeightDefinitionService : ServiceTemplate, ISurveyWeightDefinitionService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(SurveyWeightDefinition));
#endregion
public SurveyWeightDefinitionService() { }
private void MapObject(SurveyWeightDefinition oSurveyWeightDefinition, DataReader oReader)
{
oSurveyWeightDefinition.SurveyID = oReader.GetID("SurveyID");
oSurveyWeightDefinition.FromWeight = oReader.GetDouble("FromWeight").Value;
oSurveyWeightDefinition.ToWeight = oReader.GetDouble("ToWeight").Value;
oSurveyWeightDefinition.Remark = oReader.GetString("Remark");
this.SetObjectState(oSurveyWeightDefinition, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
SurveyWeightDefinition oSurveyWeightDefinition = new SurveyWeightDefinition();
MapObject(oSurveyWeightDefinition, oReader);
return oSurveyWeightDefinition as T;
}
#region Service implementation
public ObjectsTemplate<SurveyWeightDefinition> GetSurveyWeightDefinition(ID surveyId)
{
#region Cache Header
ObjectsTemplate<SurveyWeightDefinition> oSurveyWeightDefinitions = _cache["GetSurveyWeightDefinition",surveyId] as ObjectsTemplate<SurveyWeightDefinition>;
if (oSurveyWeightDefinitions != null)
return oSurveyWeightDefinitions;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SurveyWeightDefinitionDA.GetSurveyWeightDefinition(tc,surveyId.Integer));
oSurveyWeightDefinitions = this.CreateObjects<SurveyWeightDefinition>(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(oSurveyWeightDefinitions, "GetSurveyWeightDefinition", surveyId);
#endregion
return oSurveyWeightDefinitions;
}
public ObjectsTemplate<SurveyWeightDefinition> GetSurveyWeightDefinition()
{
#region Cache Header
ObjectsTemplate<SurveyWeightDefinition> oSurveyWeightDefinitions = _cache["GetSurveyWeightDefinition"] as ObjectsTemplate<SurveyWeightDefinition>;
if (oSurveyWeightDefinitions != null)
return oSurveyWeightDefinitions;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SurveyWeightDefinitionDA.GetSurveyWeightDefinition(tc));
oSurveyWeightDefinitions = this.CreateObjects<SurveyWeightDefinition>(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(oSurveyWeightDefinitions, "GetSurveyWeightDefinition");
#endregion
return oSurveyWeightDefinitions;
}
public ID Save(SurveyWeightDefinition oSurveyWeightDefinition)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
SurveyWeightDefinitionDA.DeleteSurveyWeightDefinition(tc, oSurveyWeightDefinition.SurveyID.Integer);
SurveyWeightDefinitionDA.Insert(tc, oSurveyWeightDefinition);
tc.End();
return oSurveyWeightDefinition.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);
SurveyWeightDefinitionDA.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
}
}