210 lines
6.9 KiB
C#
210 lines
6.9 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 System.Collections.Generic;
|
|||
|
using Payroll.BO;
|
|||
|
using Ease.CoreV35.Caching;
|
|||
|
|
|||
|
namespace Payroll.Service
|
|||
|
{
|
|||
|
[Serializable]
|
|||
|
public class QuestionAnswerService : ServiceTemplate, IQuestionAnswerService
|
|||
|
{
|
|||
|
#region Private functions and declaration
|
|||
|
Cache _cache = new Cache(typeof(QuestionAnswer));
|
|||
|
|
|||
|
#endregion
|
|||
|
public QuestionAnswerService() { }
|
|||
|
|
|||
|
private void MapObject(QuestionAnswer oQuestionAnswer, DataReader oReader)
|
|||
|
{
|
|||
|
base.SetObjectID(oQuestionAnswer, oReader.GetID("AnswerID"));
|
|||
|
oQuestionAnswer.AnswerID = oReader.GetID("AnswerID");
|
|||
|
oQuestionAnswer.QuestionID = oReader.GetInt32("QuestionID").GetValueOrDefault();
|
|||
|
oQuestionAnswer.AnswerBody = oReader.GetString("ANSWERBODY");
|
|||
|
oQuestionAnswer.Image = oReader.GetString("Image");
|
|||
|
oQuestionAnswer.IsCorrect = oReader.GetBoolean("IsCorrect").GetValueOrDefault();
|
|||
|
oQuestionAnswer.DisplayOrder = oReader.GetInt32("DisplayOrder").GetValueOrDefault();
|
|||
|
oQuestionAnswer.Weight = oReader.GetDouble("Weight").GetValueOrDefault();
|
|||
|
this.SetObjectState(oQuestionAnswer, Ease.CoreV35.ObjectState.Saved);
|
|||
|
}
|
|||
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
{
|
|||
|
QuestionAnswer oQuestionAnswer = new QuestionAnswer();
|
|||
|
MapObject(oQuestionAnswer, oReader);
|
|||
|
return oQuestionAnswer as T;
|
|||
|
}
|
|||
|
protected QuestionAnswer CreateObject(DataReader oReader)
|
|||
|
{
|
|||
|
QuestionAnswer oQuestionAnswer = new QuestionAnswer();
|
|||
|
MapObject(oQuestionAnswer, oReader);
|
|||
|
return oQuestionAnswer;
|
|||
|
}
|
|||
|
#region Service implementation
|
|||
|
|
|||
|
|
|||
|
public QuestionAnswer Get(ID id)
|
|||
|
{
|
|||
|
QuestionAnswer oQuestionAnswer = new QuestionAnswer();
|
|||
|
#region Cache Header
|
|||
|
oQuestionAnswer = (QuestionAnswer)_cache["Get", id.Integer];
|
|||
|
if (oQuestionAnswer != null)
|
|||
|
return oQuestionAnswer;
|
|||
|
#endregion
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(QuestionAnswerDA.Get(tc, id.Integer));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oQuestionAnswer = this.CreateObject<QuestionAnswer>(oreader);
|
|||
|
}
|
|||
|
oreader.Close();
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException("Failed to Get QuestionAnswer", e);
|
|||
|
#endregion
|
|||
|
}
|
|||
|
#region Cache Footer
|
|||
|
_cache.Add(oQuestionAnswer, "Get", id.Integer);
|
|||
|
#endregion
|
|||
|
return oQuestionAnswer;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<QuestionAnswer> Get()
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<QuestionAnswer> oQuestionAnswers = _cache["Get"] as ObjectsTemplate<QuestionAnswer>;
|
|||
|
if (oQuestionAnswers != null)
|
|||
|
return oQuestionAnswers;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader dr = new DataReader(QuestionAnswerDA.Get(tc));
|
|||
|
oQuestionAnswers = this.CreateObjects<QuestionAnswer>(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(oQuestionAnswers, "Get");
|
|||
|
#endregion
|
|||
|
return oQuestionAnswers;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<QuestionAnswer> GetByQuestionID(ID questionID)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<QuestionAnswer> oQuestionAnswers = _cache["Get", questionID] as ObjectsTemplate<QuestionAnswer>;
|
|||
|
if (oQuestionAnswers != null)
|
|||
|
return oQuestionAnswers;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader dr = new DataReader(QuestionAnswerDA.GetByQuestionID(tc, questionID.Integer));
|
|||
|
oQuestionAnswers = this.CreateObjects<QuestionAnswer>(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(oQuestionAnswers, "Get", questionID);
|
|||
|
#endregion
|
|||
|
return oQuestionAnswers;
|
|||
|
}
|
|||
|
|
|||
|
public ID Save(QuestionAnswer oQuestionAnswer)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
|
|||
|
if (oQuestionAnswer.IsNew)
|
|||
|
{
|
|||
|
|
|||
|
//int id = tc.GenerateID("QuestionAnswer", "QuestionAnswerID");
|
|||
|
//base.SetObjectID(oQuestionAnswer, ID.FromInteger(id));
|
|||
|
|
|||
|
|
|||
|
QuestionAnswerDA.Insert(tc, oQuestionAnswer);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
QuestionAnswerDA.Update(tc, oQuestionAnswer);
|
|||
|
}
|
|||
|
tc.End();
|
|||
|
return oQuestionAnswer.AnswerID;
|
|||
|
}
|
|||
|
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);
|
|||
|
QuestionAnswerDA.Delete(tc, id.Integer);
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|