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

225 lines
7.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35;
using Payroll.BO;
using Ease.CoreV35.Caching;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
namespace Payroll.Service
{
[Serializable]
public class HRJoiningQuestionaryService : ServiceTemplate, IHRJoiningQuestionaryService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(HRJoiningQuestionary));
#endregion
#region Object Mapping
private void MapObject(HRJoiningQuestionary oHrJoiningQuestionary, DataReader oReader)
{
SetObjectID(oHrJoiningQuestionary,oReader.GetID("QuestionaryID"));
oHrJoiningQuestionary.QuestionIndex = (int)oReader.GetInt32("QuestionIndex");
oHrJoiningQuestionary.QuestionNo = oReader.GetString("QuestionNo");
oHrJoiningQuestionary.Description = oReader.GetString("Description");
oHrJoiningQuestionary.IsPrimary = (EnumIsPrimary)oReader.GetInt32("IsPrimary");
oHrJoiningQuestionary.AnsDatatype = (EnumAnswerType)oReader.GetInt32("AnsDatatype");
SetObjectState(oHrJoiningQuestionary,ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
HRJoiningQuestionary oHRJoiningQuestionary=new HRJoiningQuestionary();
MapObject(oHRJoiningQuestionary, oReader);
return oHRJoiningQuestionary as T;
}
#endregion
#region Service Implementation
public HRJoiningQuestionary Get(ID nID)
{
HRJoiningQuestionary oHRJoiningQuestionary = new HRJoiningQuestionary();
#region Cache Header
oHRJoiningQuestionary = _cache["Get", nID] as HRJoiningQuestionary;
if (oHRJoiningQuestionary != null)
return oHRJoiningQuestionary;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HRJoiningQuestionaryDA.Get(tc, nID));
if (oreader.Read())
{
oHRJoiningQuestionary = CreateObject<HRJoiningQuestionary>(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(oHRJoiningQuestionary, "Get", nID);
#endregion
return oHRJoiningQuestionary;
}
public ObjectsTemplate<HRJoiningQuestionary> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<HRJoiningQuestionary> oHRJoiningQuestionaries = _cache["Get"] as ObjectsTemplate<HRJoiningQuestionary>;
if (oHRJoiningQuestionaries != null)
return oHRJoiningQuestionaries;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HRJoiningQuestionaryDA.Get(tc,status));
// if (oreader.Read())
//{
oHRJoiningQuestionaries = this.CreateObjects<HRJoiningQuestionary>(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(oHRJoiningQuestionaries, "Get");
#endregion
return oHRJoiningQuestionaries;
}
public ObjectsTemplate<HRJoiningQuestionary> GetByQuestionNo(string sQuesNo)
{
#region Cache Header
ObjectsTemplate<HRJoiningQuestionary> oHRJoiningQuestionaries = _cache["Get"] as ObjectsTemplate<HRJoiningQuestionary>;
if (oHRJoiningQuestionaries != null)
return oHRJoiningQuestionaries;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HRJoiningQuestionaryDA.GetByQuestionNo(tc, sQuesNo));
oHRJoiningQuestionaries = this.CreateObjects<HRJoiningQuestionary>(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(oHRJoiningQuestionaries, "Get");
#endregion
return oHRJoiningQuestionaries;
}
public ID Save(HRJoiningQuestionary item)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (item.IsNew)
{
int id = tc.GenerateID("HRJoiningQuestionary", "QuestionaryID");
SetObjectID(item, ID.FromInteger(id));
int quesIndex = tc.GenerateID("HRJoiningQuestionary", "QuestionIndex");
item.QuestionIndex = quesIndex;
HRJoiningQuestionaryDA.Insert(tc, item);
}
else
{
HRJoiningQuestionaryDA.Update(tc, item);
}
tc.End();
return item.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);
HRJoiningQuestionaryDA.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
}
}