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

237 lines
7.9 KiB
C#

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
{
[Serializable]
public class QuestionCategoryService:ServiceTemplate,IQuestionCategoryService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(QuestionCategory));
#endregion
public QuestionCategoryService() { }
private void MapObject(QuestionCategory oQuestionCategory, DataReader oReader)
{
base.SetObjectID(oQuestionCategory, oReader.GetID("QuestionCategoryID"));
oQuestionCategory.Code = oReader.GetString("Code");
oQuestionCategory.Description = oReader.GetString("Description");
//oQuestionCategory.Sequence = oReader.GetInt32("SequenceNo").Value;
oQuestionCategory.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oQuestionCategory.CreatedBy = oReader.GetID("CreatedBy");
oQuestionCategory.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oQuestionCategory.ModifiedBy = oReader.GetID("ModifiedBy");
oQuestionCategory.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oQuestionCategory, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
QuestionCategory oQuestionCategory = new QuestionCategory();
MapObject(oQuestionCategory, oReader);
return oQuestionCategory as T;
}
protected QuestionCategory CreateObject(DataReader oReader)
{
QuestionCategory oQuestionCategory = new QuestionCategory();
MapObject(oQuestionCategory, oReader);
return oQuestionCategory;
}
#region Service implementation
public string GetNextCode()
{
TransactionContext tc = null;
string _code = "";
try
{
tc = TransactionContext.Begin();
_code = GlobalFunctionService.GetMaxCode(tc, "QuestionCategory", "codeautogenerate", "QuestionCategory", "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 QuestionCategory Get(ID id)
{
QuestionCategory oQuestionCategory = new QuestionCategory();
#region Cache Header
oQuestionCategory = _cache["Get", id] as QuestionCategory;
if (oQuestionCategory != null)
return oQuestionCategory;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(QuestionCategoryDA.Get(tc, id));
if (oreader.Read())
{
oQuestionCategory = this.CreateObject<QuestionCategory>(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(oQuestionCategory, "Get", id);
#endregion
return oQuestionCategory;
}
public QuestionCategory Get(string sCode)
{
QuestionCategory oQuestionCategory = new QuestionCategory();
#region Cache Header
oQuestionCategory = _cache["Get", sCode] as QuestionCategory;
if (oQuestionCategory != null)
return oQuestionCategory;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(QuestionCategoryDA.Get(tc, sCode));
if (oreader.Read())
{
oQuestionCategory = this.CreateObject<QuestionCategory>(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(oQuestionCategory, "Get", sCode);
#endregion
return oQuestionCategory;
}
public ObjectsTemplate<QuestionCategory> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<QuestionCategory> QuestionCategorys = _cache["Get"] as ObjectsTemplate<QuestionCategory>;
if (QuestionCategorys != null)
return QuestionCategorys;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(QuestionCategoryDA.Get(tc, status));
QuestionCategorys = this.CreateObjects<QuestionCategory>(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(QuestionCategorys, "Get",status);
#endregion
return QuestionCategorys;
}
public ID Save(QuestionCategory oQuestionCategory)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oQuestionCategory.IsNew)
{
int id = tc.GenerateID("QuestionCategory", "QuestionCategoryID");
// int seqID = tc.GenerateID("QuestionCategory", "SequenceNO");
base.SetObjectID(oQuestionCategory, ID.FromInteger(id));
// oQuestionCategory.Sequence = seqID;
QuestionCategoryDA.Insert(tc, oQuestionCategory);
}
else
{
QuestionCategoryDA.Update(tc, oQuestionCategory);
}
tc.End();
return oQuestionCategory.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);
QuestionCategoryDA.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
}
}