378 lines
9.1 KiB
C#
378 lines
9.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Ease.CoreV35;
|
|
using Ease.CoreV35.Model;
|
|
using Ease.CoreV35.Caching;
|
|
using System.Data.Linq.Mapping;
|
|
|
|
namespace Payroll.BO
|
|
{
|
|
#region Question
|
|
[Serializable]
|
|
public class Question : AuditTrailBase
|
|
{
|
|
|
|
#region Cache Store
|
|
|
|
private static Cache _cache = new Cache(typeof(Question));
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
#region Input validator
|
|
//public string[] InputValidator()
|
|
//{
|
|
// string[] sErrorString = new string[2];
|
|
// if (this.Code == "")
|
|
// {
|
|
// sErrorString[0] = "Code can not be empty";
|
|
// sErrorString[1] = "Code";
|
|
// return sErrorString;
|
|
// }
|
|
// if (this.Name == "")
|
|
// {
|
|
// sErrorString[0] = "Description can not be empty";
|
|
// sErrorString[1] = "Description";
|
|
// return sErrorString;
|
|
// }
|
|
|
|
// sErrorString = null;
|
|
// return sErrorString;
|
|
//}
|
|
#endregion
|
|
|
|
public Question()
|
|
{
|
|
_questionID = null;
|
|
_questionNo = string.Empty;
|
|
_categoryID = 0;
|
|
_questionBody = string.Empty;
|
|
_image = string.Empty;
|
|
_isMultiple = false;
|
|
_isPublished = false;
|
|
_creationDate = DateTime.MinValue;
|
|
_userID = 0;
|
|
_questionType = 0;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
#region QuestionID : ID
|
|
|
|
private ID _questionID;
|
|
public ID QuestionID
|
|
{
|
|
get { return _questionID; }
|
|
set
|
|
{
|
|
base.OnPropertyChange<ID>("QuestionID", _questionID, value);
|
|
_questionID = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region QuestionNo : string
|
|
|
|
private string _questionNo;
|
|
public string QuestionNo
|
|
{
|
|
get { return _questionNo; }
|
|
set
|
|
{
|
|
base.OnPropertyChange<string>("QuestionNo", _questionNo, value);
|
|
_questionNo = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CategoryID : int
|
|
|
|
private int _categoryID;
|
|
public int CategoryID
|
|
{
|
|
get { return _categoryID; }
|
|
set
|
|
{
|
|
base.OnPropertyChange<int>("CategoryID", _categoryID, value);
|
|
_categoryID = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
#region QuestionBody : string
|
|
|
|
private string _questionBody;
|
|
public string QuestionBody
|
|
{
|
|
get { return _questionBody; }
|
|
set
|
|
{
|
|
base.OnPropertyChange<string>("QuestionBody", _questionBody, value);
|
|
_questionBody = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Image : string
|
|
|
|
private string _image;
|
|
public string Image
|
|
{
|
|
get { return _image; }
|
|
set
|
|
{
|
|
base.OnPropertyChange<string>("Image", _image, value);
|
|
_image = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IsMultiple : bool
|
|
|
|
private bool _isMultiple;
|
|
public bool IsMultiple
|
|
{
|
|
get { return _isMultiple; }
|
|
set
|
|
{
|
|
base.OnPropertyChange<bool>("IsMultiple", _isMultiple, value);
|
|
_isMultiple = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IsPublished : bool
|
|
|
|
private bool _isPublished;
|
|
public bool IsPublished
|
|
{
|
|
get { return _isPublished; }
|
|
set
|
|
{
|
|
base.OnPropertyChange<bool>("IsPublished", _isPublished, value);
|
|
_isPublished = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CreationDate : DateTime
|
|
|
|
private DateTime _creationDate;
|
|
public DateTime CreationDate
|
|
{
|
|
get { return _creationDate; }
|
|
set
|
|
{
|
|
base.OnPropertyChange<DateTime>("monthDate", _creationDate, value);
|
|
_creationDate = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region UserID : int
|
|
|
|
private int _userID;
|
|
public int UserID
|
|
{
|
|
get { return _userID; }
|
|
set
|
|
{
|
|
base.OnPropertyChange<int>("QuestionID", _userID, value);
|
|
_userID = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region QuestionType : EnumSurveyQuestionType
|
|
|
|
private EnumSurveyQuestionType _questionType;
|
|
public EnumSurveyQuestionType QuestionType
|
|
{
|
|
get { return _questionType; }
|
|
set
|
|
{
|
|
base.OnPropertyChange<short>("QuestionType", (short)_questionType, (short)value);
|
|
_questionType = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region QuestionAnswers property
|
|
private ObjectsTemplate<QuestionAnswer> _questionAnswers;
|
|
public ObjectsTemplate<QuestionAnswer> QuestionAnswers
|
|
{
|
|
get
|
|
{
|
|
if (_questionAnswers == null)
|
|
{
|
|
_questionAnswers = new ObjectsTemplate<QuestionAnswer>();
|
|
if (!this.ID.IsUnassigned)
|
|
_questionAnswers = QuestionAnswer.GetByQuestionID(this.ID);
|
|
}
|
|
|
|
return _questionAnswers;
|
|
}
|
|
set { _questionAnswers = value; }
|
|
}
|
|
#endregion
|
|
|
|
#region Category
|
|
private QuestionCategory _category;
|
|
public QuestionCategory Category
|
|
{
|
|
get
|
|
{
|
|
if (_category == null)
|
|
{
|
|
_category = QuestionCategory.Get(ID.FromInteger(_categoryID));
|
|
}
|
|
return _category;
|
|
}
|
|
set { _category = value; }
|
|
}
|
|
#endregion
|
|
|
|
public string QuestionCategoryDes
|
|
{
|
|
get
|
|
{
|
|
if (this.Category == null)
|
|
return "";
|
|
return this.Category.Description;
|
|
}
|
|
}
|
|
|
|
#region Service Factory IPFTransactionService : IPFTransactionService
|
|
|
|
internal static IQuestionService Service
|
|
{
|
|
get { return Services.Factory.CreateService<IQuestionService>(typeof(IQuestionService)); }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region Functions
|
|
|
|
|
|
|
|
public Question Get(ID nID)
|
|
{
|
|
Question oQuestion = null;
|
|
#region Cache Header
|
|
oQuestion = (Question)_cache["Get", ID];
|
|
if (oQuestion != null)
|
|
return oQuestion;
|
|
#endregion
|
|
oQuestion = Question.Service.Get(nID);
|
|
#region Cache Footer
|
|
_cache.Add(oQuestion, "Get", ID);
|
|
#endregion
|
|
return oQuestion;
|
|
}
|
|
|
|
public static ObjectsTemplate<Question> Get()
|
|
{
|
|
#region cache header
|
|
ObjectsTemplate<Question> Questions = _cache["Get"] as ObjectsTemplate<Question>;
|
|
if (Questions != null)
|
|
return Questions;
|
|
#endregion
|
|
try
|
|
{
|
|
Questions = Service.Get();
|
|
}
|
|
catch (ServiceException e)
|
|
{
|
|
throw new Exception(e.Message, e);
|
|
}
|
|
|
|
#region cache footer
|
|
_cache.Add(Questions, "Get");
|
|
#endregion
|
|
|
|
return Questions;
|
|
}
|
|
|
|
|
|
public static ObjectsTemplate<Question> GetByCategory(ID categoryID)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<Question> Questions = _cache["Get", categoryID] as ObjectsTemplate<Question>;
|
|
if (Questions != null)
|
|
return Questions;
|
|
|
|
#endregion
|
|
|
|
try
|
|
{
|
|
Questions = Service.GetByCategory(categoryID);
|
|
}
|
|
catch (ServiceException e)
|
|
{
|
|
throw new Exception(e.Message, e);
|
|
}
|
|
|
|
#region Cache Footer
|
|
|
|
_cache.Add(Questions, "Get", categoryID);
|
|
|
|
#endregion
|
|
|
|
return Questions;
|
|
}
|
|
|
|
public bool IsTagged()
|
|
{
|
|
if (this.IsNew || this.ID.IsUnassigned)
|
|
return false;
|
|
return Service.IsTagged(this.ID);
|
|
}
|
|
|
|
public ID Save()
|
|
{
|
|
base.SetAuditTrailProperties();
|
|
return Question.Service.Save(this);
|
|
}
|
|
|
|
public void Delete(ID id)
|
|
{
|
|
Question.Service.Delete(id);
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region IQuestion Service
|
|
|
|
public interface IQuestionService
|
|
{
|
|
Question Get(ID id);
|
|
ObjectsTemplate<Question> Get();
|
|
ObjectsTemplate<Question> GetByCategory(ID categoryID);
|
|
ID Save(Question item);
|
|
void Delete(ID id);
|
|
bool IsTagged(ID id);
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|