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 { [Serializable] public class Survey : AuditTrailBase { #region Cache Store private static Cache _cache = new Cache(typeof(Survey)); #endregion #region Constructor public Survey() { _SurveyID = null; _title = string.Empty; _categoryID = 0; _description = string.Empty; _fromDate = DateTime.MinValue; _toDate = DateTime.MinValue; _publishDate = null; _isPublished = false; _isForCelyStoped = false; _surveyType = EnumSurveyType.None; } #endregion #region Properties #region SurveyID : ID private ID _SurveyID; public ID SurveyID { get { return _SurveyID; } set { base.OnPropertyChange("SurveyID", _SurveyID, value); _SurveyID = value; } } #endregion #region Title : string private string _title; public string Title { get { return _title; } set { base.OnPropertyChange("Title", _title, value); _title = value; } } #endregion #region CategoryID : int private int _categoryID; public int CategoryID { get { return _categoryID; } set { base.OnPropertyChange("CategoryID", _categoryID, value); _categoryID = value; } } #endregion #region Description : string private string _description; public string Description { get { return _description; } set { base.OnPropertyChange("Description", _description, value); _description = value; } } #endregion #region PublishDate : DateTime private DateTime? _publishDate; public DateTime? PublishDate { get { return _publishDate; } set { if (this._publishDate != value) base.OnPropertyChange("PublishDate", _publishDate, value); _publishDate = value; } } #endregion #region FromDate : DateTime private DateTime _fromDate; public DateTime FromDate { get { return _fromDate; } set { base.OnPropertyChange("FromDate", _fromDate, value); _fromDate = value; } } #endregion #region ToDate : DateTime private DateTime _toDate; public DateTime ToDate { get { return _toDate; } set { base.OnPropertyChange("ToDate", _toDate, value); _toDate = value; } } #endregion #region Survey Type : EnumSurveyType private EnumSurveyType _surveyType; public EnumSurveyType SurveyType { get { return _surveyType; } set { base.OnPropertyChange("SurveyType", (short)_surveyType,(short) value); _surveyType = value; } } #endregion #region IsForCelyStoped : bool private bool _isForCelyStoped; public bool IsForCelyStoped { get { return _isForCelyStoped; } set { base.OnPropertyChange("IsForCelyStoped", _isForCelyStoped, value); _isForCelyStoped = value; } } #endregion #region IsPublished : bool private bool _isPublished; public bool IsPublished { get { return _isPublished; } set { base.OnPropertyChange("IsPublished", _isPublished, value); _isPublished = value; } } #endregion #region Category private SurveyCategory _category; public SurveyCategory Category { get { if (_category == null) { _category = SurveyCategory.Get(ID.FromInteger(_categoryID)); } return _category; } set { _category = value; } } #endregion #region SurveyWeightDefinition private ObjectsTemplate _SurveyWeightDefinitions; public ObjectsTemplate SurveyWeightDefinitions { get { if (_SurveyWeightDefinitions == null) { _SurveyWeightDefinitions = new ObjectsTemplate(); if (!this.ID.IsUnassigned) _SurveyWeightDefinitions = SurveyWeightDefinition.GetSurveyWeightDefinition(this.ID); } return _SurveyWeightDefinitions; } set { _SurveyWeightDefinitions = value; } } #endregion #region Service Factory IPFTransactionService : IPFTransactionService internal static ISurveyService Service { get { return Services.Factory.CreateService(typeof(ISurveyService)); } } #endregion #region SurveyQuestion property private ObjectsTemplate _surveyQuestions; public ObjectsTemplate SurveyQuestions { get { if (_surveyQuestions == null) { _surveyQuestions = new ObjectsTemplate(); if (!this.ID.IsUnassigned) _surveyQuestions = SurveyQuestion.GetSurveyQuestion(this.ID); } return _surveyQuestions; } set { _surveyQuestions = value; } } #endregion #region SurveyQuestion property private ObjectsTemplate _surveyOrganizations; public ObjectsTemplate SurveyOrganizations { get { if (_surveyOrganizations == null || _surveyOrganizations.Count==0) { _surveyOrganizations = new ObjectsTemplate(); if (!this.ID.IsUnassigned) _surveyOrganizations = SurveyOrganization.GetSurveyOrganization(this.ID); } return _surveyOrganizations; } set { _surveyOrganizations = value; } } #endregion #region SurveyEmployee property private ObjectsTemplate _surveyEmployees; public ObjectsTemplate SurveyEmployees { get { if (_surveyEmployees == null) { _surveyEmployees = new ObjectsTemplate(); if (!this.ID.IsUnassigned) _surveyEmployees = SurveyEmployee.GetSurveyEmployee(this.ID); } return _surveyEmployees; } set { _surveyEmployees = value; } } #endregion #region SurveyAnswerCount property private ObjectsTemplate _surveyAnswerCounts; public ObjectsTemplate SurveyAnswerCounts { get { if (_surveyAnswerCounts == null) { _surveyAnswerCounts = new ObjectsTemplate(); if (!this.ID.IsUnassigned) _surveyAnswerCounts = SurveyAnswerCount.GetSurveyAnswerCount(this.ID); } return _surveyAnswerCounts; } set { _surveyAnswerCounts = value; } } #endregion #region SurveyResult property private ObjectsTemplate _surveyResults; public ObjectsTemplate SurveyResults { get { if (_surveyResults == null) { _surveyResults = new ObjectsTemplate(); if (!this.ID.IsUnassigned) _surveyResults = SurveyResult.GetSurveyResult(this.ID); } return _surveyResults; } set { _surveyResults = value; } } #endregion #endregion #region Functions public static Survey Get(ID nID) { Survey oSurvey = null; #region Cache Header oSurvey = (Survey)_cache["Get", oSurvey]; if (oSurvey != null) return oSurvey; #endregion oSurvey = Survey.Service.Get(nID); #region Cache Footer _cache.Add(oSurvey, "Get", oSurvey); #endregion return oSurvey; } public static ObjectsTemplate Get() { #region cache header ObjectsTemplate Surveys = _cache["Get"] as ObjectsTemplate; if (Surveys != null) return Surveys; #endregion try { Surveys = Service.Get(); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region cache footer _cache.Add(Surveys, "Get"); #endregion return Surveys; } public static ObjectsTemplate Get(DateTime today) { ObjectsTemplate oSurvey = null; #region Cache Header oSurvey = (ObjectsTemplate)_cache["Get"]; if (oSurvey != null) return oSurvey; #endregion oSurvey = Service.Get(today); #region Cache Footer _cache.Add(oSurvey, "Get"); #endregion return oSurvey; } public static ObjectsTemplate Get(DateTime fromDT, DateTime toDT) { ObjectsTemplate oSurvey = null; oSurvey = Service.Get(fromDT, toDT); return oSurvey; } public static ObjectsTemplate Get(int categoryId, DateTime fromDT, DateTime toDT) { ObjectsTemplate oSurvey = null; oSurvey = Service.Get(categoryId, fromDT, toDT); return oSurvey; } public static ObjectsTemplate GetSurveyForEmployee(Employee oEmp,DateTime dt) { ObjectsTemplate oNewSurveys = new ObjectsTemplate(); ObjectsTemplate oSurveys = Survey.Get(dt); foreach (Survey sr in oSurveys) { SurveyEmployee oSurveyEmployee = sr.SurveyEmployees.Find(delegate(SurveyEmployee se) { return se.EmployeeID == oEmp.ID.Integer; }); if (oSurveyEmployee == null) { SurveyOrganization oSurveyOrganization = sr.SurveyOrganizations.Find(delegate(SurveyOrganization so) { return so.DepartmentID == oEmp.DepartmentID || so.LocationID == oEmp.LocationID || so.GradeID == oEmp.GradeID; }); if(oSurveyOrganization !=null) oNewSurveys.Add(sr); } else { oNewSurveys.Add(sr); } } return oNewSurveys; } public static ObjectsTemplate Get(int categoryId) { #region Cache Header ObjectsTemplate Surveys = _cache["Get", categoryId] as ObjectsTemplate; if (Surveys != null) return Surveys; #endregion try { Surveys = Service.Get(categoryId); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(Surveys, "Get", categoryId); #endregion return Surveys; } public ID Save() { base.SetAuditTrailProperties(); return Survey.Service.Save(this); } public void Delete(ID id) { Survey.Service.Delete(id); } public void Publish(Survey survey) { Survey.Service.Publish(survey); } public void Stop(Survey survey) { Survey.Service.Stop(survey); } #endregion } #region ISurvey Service public interface ISurveyService { Survey Get(ID id); ObjectsTemplate Get(); ObjectsTemplate Get(int categoryId); ObjectsTemplate Get(DateTime today); //ObjectsTemplate Get(Employee oEmp); ObjectsTemplate Get(DateTime fromDT, DateTime toDT); ObjectsTemplate Get(int categoryId, DateTime fromDT, DateTime toDT); ID Save(Survey item); void Delete(ID id); void Publish(Survey survey); void Stop(Survey survey); } #endregion }