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

282 lines
7.4 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 class Institution
[Serializable]
public class Institution : BasicBaseObject
{
#region cache store
private static Cache _cache = new Cache(typeof(Institution));
#endregion
#region constructor
public Institution()
{
_code = string.Empty;
_name = string.Empty;
_educationTypeID = null;
_type = 0;
_status = EnumStatus.Active;
}
#region Input validator
public string[] InputValidator()
{
string[] sErrorString = new string[3];
if (this.Code == "")
{
sErrorString[0] = "Code can not be empty";
sErrorString[1] = "Code";
return sErrorString;
}
if (this.Name == "")
{
sErrorString[0] = "Name can not be empty";
sErrorString[1] = "Name";
return sErrorString;
}
if (this.EducationTypeID == null)
{
sErrorString[0] = "Please select education type.";
sErrorString[1] = "EducationTypeID";
return sErrorString;
}
sErrorString = null;
return sErrorString;
}
#endregion
#endregion
#region properties
#region code : string
private string _code;
public string Code
{
get { return _code; }
set
{ base.OnPropertyChange<string>("CODE", _code, value);
_code = value;
}
}
#endregion
#region name : string
private string _name;
public string Name
{
get { return _name; }
set
{ base.OnPropertyChange<string>("NAME", _name, value);
_name = value;
}
}
#endregion
#region type : int
private int _type;
public int Type
{
get { return _type; }
set
{
base.OnPropertyChange<int>("TYPE", _type, value);
_type = value;
}
}
#endregion
#region EducationTypeID
private ID _educationTypeID;
public ID EducationTypeID
{
get { return _educationTypeID; }
set
{
base.OnPropertyChange<ID>("EDUCATIONTYPEID", _educationTypeID, value);
_educationTypeID = value;
}
}
#endregion
#region Service Factory IInstitutionService : IInstitutionService
internal static IInstitutionService Service
{
get { return Services.Factory.CreateService<IInstitutionService>(typeof(IInstitutionService)); }
}
#endregion
#endregion
#region Function
public static Institution Get(ID nID)
{
Institution oInstitution = null;
#region Cache Header
oInstitution = (Institution)_cache["Get", nID];
if (oInstitution != null)
return oInstitution;
#endregion
oInstitution = Institution.Service.Get(nID);
#region Cache Footer
_cache.Add(oInstitution, "Get", nID);
#endregion
return oInstitution;
}
public static Institution Get(string sCode)
{
Institution oInstitution = null;
#region Cache Header
oInstitution = (Institution)_cache["Get", sCode];
if (oInstitution != null)
return oInstitution;
#endregion
oInstitution = Institution.Service.Get(sCode);
#region Cache Footer
_cache.Add(oInstitution, "Get", sCode);
#endregion
return oInstitution;
}
public static ObjectsTemplate<Institution> Get()
{
#region cache header
ObjectsTemplate<Institution> institutions = _cache["Get"] as ObjectsTemplate<Institution>;
if (institutions != null)
return institutions;
#endregion
try
{
institutions = Service.Get();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region cache footer
_cache.Add(institutions, "Get");
#endregion
return institutions;
}
public static ObjectsTemplate<Institution> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<Institution> institutions = _cache["Get", status] as ObjectsTemplate<Institution>;
if (institutions != null)
return institutions;
#endregion
try
{
institutions = Service.Get(status);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(institutions, "Get", status);
#endregion
return institutions;
}
public static ObjectsTemplate<Institution> GetByInstituteType(EnmInstituteType type)
{
#region Cache Header
ObjectsTemplate<Institution> institutions = _cache["GetByInstituteType", type] as ObjectsTemplate<Institution>;
if (institutions != null)
return institutions;
#endregion
try
{
institutions = Service.GetByInstituteType(type);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(institutions, "GetByInstituteType", type);
#endregion
return institutions;
}
public ID Save()
{
this.SetAuditTrailProperties();
if (this.IsExists(this.Code))
throw new Exception("Duplicate code is not allowed.");
return Institution.Service.Save(this);
}
public void Delete(ID id)
{
Institution.Service.Delete(id);
}
private bool IsExists(string Code)
{
try
{
bool isExists = false;
if (this.Code != null)
{
isExists = Institution.Service.IsExists(Code);
}
return isExists;
}
catch (ServiceException e)
{
throw new ServiceException(e.Message, e);
}
}
#endregion
}
#endregion
#region IInstitution Service
public interface IInstitutionService
{
Institution Get(ID id);
Institution Get(string sCode);
ObjectsTemplate<Institution> Get();
ObjectsTemplate<Institution> Get(EnumStatus status);
ObjectsTemplate<Institution> GetByInstituteType(EnmInstituteType type);
ID Save(Institution item);
void Delete(ID id);
bool IsExists(string Code);
}
#endregion
}