350 lines
9.6 KiB
C#
350 lines
9.6 KiB
C#
using System;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.DataAccess;
|
|
using HRM.BO;
|
|
using System.Collections.Generic;
|
|
using Ease.Core.Utility;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
#region class InstitutionService
|
|
|
|
public class InstitutionService : ServiceTemplate, IInstitutionService
|
|
{
|
|
#region constructor
|
|
|
|
public InstitutionService()
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Object
|
|
|
|
private void MapObject(Institution oInstitution, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oInstitution, oReader.GetInt32("INSTITUTIONID").Value);
|
|
oInstitution.Code = oReader.GetString("CODE");
|
|
oInstitution.Name = oReader.GetString("NAME");
|
|
oInstitution.Type =(EnmInstituteType) oReader.GetInt32("TYPE").Value;
|
|
oInstitution.EducationTypeID = oReader.GetInt32("EducationTypeID", 0);
|
|
oInstitution.Sequence = oReader.GetInt32("SequenceNo").Value;
|
|
oInstitution.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|
oInstitution.CreatedBy = oReader.GetInt32("CreatedBy", 0);
|
|
oInstitution.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
oInstitution.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
|
|
oInstitution.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
oInstitution.BoardRequired = oReader.GetBoolean("BoardRequired", true, false);
|
|
|
|
|
|
this.SetObjectState(oInstitution, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
Institution oInstitution = new Institution();
|
|
MapObject(oInstitution, oReader);
|
|
return oInstitution as T;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Service implementation
|
|
|
|
public Institution Get(int id)
|
|
{
|
|
Institution oInstitution = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(InstitutionDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oInstitution = this.CreateObject<Institution>(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
|
|
}
|
|
|
|
return oInstitution;
|
|
}
|
|
|
|
public Institution Get(string sCode)
|
|
{
|
|
Institution oInstitution = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(InstitutionDA.Get(tc, sCode));
|
|
if (oreader.Read())
|
|
{
|
|
oInstitution = this.CreateObject<Institution>(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
|
|
}
|
|
|
|
return oInstitution;
|
|
}
|
|
|
|
public List<Institution> Get()
|
|
{
|
|
List<Institution> institutions = new List<Institution>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(InstitutionDA.Get(tc));
|
|
institutions = this.CreateObjects<Institution>(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
|
|
}
|
|
|
|
return institutions;
|
|
}
|
|
|
|
public List<Institution> Get(EnumStatus status)
|
|
{
|
|
List<Institution> institutions = new List<Institution>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(InstitutionDA.Get(tc, status));
|
|
institutions = this.CreateObjects<Institution>(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
|
|
}
|
|
|
|
return institutions;
|
|
}
|
|
public List<Institution> Get(EnumStatus status, int payrolltypeid)
|
|
{
|
|
List<Institution> institutions = new List<Institution>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(InstitutionDA.Get(tc, status));
|
|
institutions = this.CreateObjects<Institution>(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
|
|
}
|
|
|
|
return institutions;
|
|
}
|
|
public List<Institution> GetByInstituteType(EnmInstituteType type)
|
|
{
|
|
List<Institution> institutions = new List<Institution>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(InstitutionDA.GetByInstituteType(tc, type));
|
|
institutions = this.CreateObjects<Institution>(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
|
|
}
|
|
|
|
return institutions;
|
|
}
|
|
|
|
public string GetNextCode()
|
|
{
|
|
TransactionContext tc = null;
|
|
string _code = "";
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
_code = GlobalFunctionService.GetMaxCode(tc, "INSTITUTION", "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 int Save(Institution oInstitution)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oInstitution.IsNew)
|
|
{
|
|
int id = tc.GenerateID("INSTITUTION", "INSTITUTIONID");
|
|
base.SetObjectID(oInstitution, id);
|
|
oInstitution.Code = GlobalFunctionService.GetMaxCode(tc, "INSTITUTION", "Code");
|
|
InstitutionDA.Insert(tc, oInstitution);
|
|
}
|
|
else
|
|
{
|
|
InstitutionDA.Update(tc, oInstitution);
|
|
}
|
|
|
|
tc.End();
|
|
return oInstitution.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(int id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
InstitutionDA.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
|
|
}
|
|
}
|
|
|
|
public bool IsExists(string Code)
|
|
{
|
|
TransactionContext tc = null;
|
|
bool isExists = false;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
isExists = InstitutionDA.IsExists(tc, Code);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException("Failed to get Skill due to " + e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return isExists;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
} |