CEL_Payroll/Payroll.Service/Basic/Service/ExitInterviewService.cs
2024-09-17 14:30:13 +06:00

353 lines
12 KiB
C#

using System;
using System.Data;
using System.Linq;
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
{
#region ExitInterview Service
[Serializable]
public class ExitInterviewService : ServiceTemplate, IExitInterviewService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(ExitInterview));
#endregion
public ExitInterviewService() { }
private void MapObject(ExitInterview oExitInterview, DataReader oReader)
{
base.SetObjectID(oExitInterview, oReader.GetID("ExitInterviewID"));
oExitInterview.EmployeeID = oReader.GetID("EmployeeID");
oExitInterview.Name = oReader.GetString("Name");
oExitInterview.JobTitle = oReader.GetString("JobTitle");
oExitInterview.DepartmentName = oReader.GetString("DepartmentName");
oExitInterview.ManagerName = oReader.GetString("ManagerName");
oExitInterview.SourceofHire = oReader.GetString("SourceofHire");
oExitInterview.HireDate = oReader.GetDateTime("HireDate");
oExitInterview.TermDate = oReader.GetDateTime("TermDate");
oExitInterview.ExitInteviewDate = oReader.GetDateTime("ExitInteviewDate").Value;
oExitInterview.CultureandClimate = oReader.GetString("CultureandClimate");
oExitInterview.CareerDevelopment = oReader.GetString("CareerDevelopment");
oExitInterview.Settingobjectives = oReader.GetString("Settingobjectives");
oExitInterview.Providingfeedbackonperformance = oReader.GetString("Providingfeedbackonperformance");
oExitInterview.Facilitatingteamwork = oReader.GetString("Facilitatingteamwork");
oExitInterview.Communicatinginformationaffects = oReader.GetString("Communicatinginformationaffects");
oExitInterview.Relationshipwithemployees = oReader.GetString("Relationshipwithemployees");
oExitInterview.Other = oReader.GetString("Other");
oExitInterview.CreatedBy = oReader.GetID("CreatedBy");
oExitInterview.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oExitInterview.ModifiedBy = oReader.GetID("ModifiedBy");
oExitInterview.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oExitInterview.AdditionalComments = oReader.GetString("AdditionalComments");
this.SetObjectState(oExitInterview, Ease.CoreV35.ObjectState.Saved);
}
private void MapReasonForLeavingObject(ReasonsForLeaving oReasonForLeaving, DataReader oReader)
{
base.SetObjectID(oReasonForLeaving, oReader.GetID("ReasonsForLeavingID"));
oReasonForLeaving.ExitInterviewID = oReader.GetID("ExitInterviewID");
oReasonForLeaving.ReasonID = oReader.GetID("ReasonID");
this.SetObjectState(oReasonForLeaving, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ExitInterview oExitInterview = new ExitInterview();
MapObject(oExitInterview, oReader);
return oExitInterview as T;
}
protected ExitInterview CreateObject(DataReader oReader)
{
ExitInterview oExitInterview = new ExitInterview();
MapObject(oExitInterview, oReader);
return oExitInterview;
}
protected ObjectsTemplate<ReasonsForLeaving> CreateReasonForLeavingObjects(DataReader oReader)
{
ObjectsTemplate<ReasonsForLeaving> oReasonsForLeavings = new ObjectsTemplate<ReasonsForLeaving>();
while (oReader.Read())
{
ReasonsForLeaving oItem = new ReasonsForLeaving();
MapReasonForLeavingObject(oItem, oReader);
oReasonsForLeavings.Add(oItem);
}
return oReasonsForLeavings;
}
protected ReasonsForLeaving CreateReasonForLeavingObject(DataReader oReader)
{
ReasonsForLeaving oReasonsForLeaving = new ReasonsForLeaving();
MapReasonForLeavingObject(oReasonsForLeaving, oReader);
return oReasonsForLeaving;
}
#region Service implementation
public ExitInterview Get(ID id)
{
ExitInterview oExitInterview = new ExitInterview();
#region Cache Header
oExitInterview = _cache["Get", id] as ExitInterview;
if (oExitInterview != null)
return oExitInterview;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ExitInterviewDA.Get(tc, id));
if (oreader.Read())
{
oExitInterview = this.CreateObject<ExitInterview>(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
}
#region Cache Footer
_cache.Add(oExitInterview, "Get", id);
#endregion
return oExitInterview;
}
public ExitInterview GetByEmployeeID(ID id)
{
ExitInterview oExitInterview = new ExitInterview();
#region Cache Header
oExitInterview = _cache["GetByEmployeeID", id] as ExitInterview;
if (oExitInterview != null)
return oExitInterview;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ExitInterviewDA.GetByEmployeeID(tc, id));
if (oreader.Read())
{
oExitInterview = this.CreateObject<ExitInterview>(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
}
#region Cache Footer
_cache.Add(oExitInterview, "GetByEmployeeID", id);
#endregion
return oExitInterview;
}
public ObjectsTemplate<ExitInterview> Get()
{
#region Cache Header
ObjectsTemplate<ExitInterview> ExitInterviews = _cache["Get"] as ObjectsTemplate<ExitInterview>;
if (ExitInterviews != null)
return ExitInterviews;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ExitInterviewDA.Get(tc));
ExitInterviews = this.CreateObjects<ExitInterview>(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(ExitInterviews, "Get");
#endregion
return ExitInterviews;
}
public ObjectsTemplate<ReasonsForLeaving> GetReasonsForLeaving(ID nExitInterviewID)
{
#region Cache Header
ObjectsTemplate<ReasonsForLeaving> oReasonsForLeaving = _cache["GetReasonsForLeaving", nExitInterviewID] as ObjectsTemplate<ReasonsForLeaving>;
if (oReasonsForLeaving != null)
return oReasonsForLeaving;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ExitInterviewDA.GetReasonsForLeaving(tc, nExitInterviewID));
oReasonsForLeaving = this.CreateReasonForLeavingObjects(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(oReasonsForLeaving, "GetReasonsForLeaving", nExitInterviewID);
#endregion
return oReasonsForLeaving;
}
public ObjectsTemplate<ExitInterview> Get(DateTime dtFrom, DateTime dtTo,int nReasonID)
{
#region Cache Header
ObjectsTemplate<ExitInterview> oExitInterview = _cache["Get", dtFrom, dtTo, nReasonID] as ObjectsTemplate<ExitInterview>;
if (oExitInterview != null)
return oExitInterview;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ExitInterviewDA.Get(tc, dtFrom, dtTo, nReasonID));
oExitInterview = this.CreateObjects<ExitInterview>(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(oExitInterview, "Get", dtFrom, dtTo, nReasonID);
#endregion
return oExitInterview;
}
public ID Save(ExitInterview oExitInterview)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oExitInterview.IsNew)
{
int id = tc.GenerateID("ExitInterview", "ExitInterviewID");
base.SetObjectID(oExitInterview, ID.FromInteger(id));
//int seqNo = tc.GenerateID("ExitInterviewes", "SequenceNO");
//oExitInterview.Sequence = seqNo;
ExitInterviewDA.Insert(tc, oExitInterview);
}
else
{
ExitInterviewDA.Update(tc, oExitInterview);
}
ExitInterviewDA.DeleteReasonsForLeaving(tc,oExitInterview.ID);
foreach (ReasonsForLeaving oObj in oExitInterview.ReasonsForLeavingCol)
{
int id = tc.GenerateID("ReasonsForLeaving", "ReasonsForLeavingID");
base.SetObjectID(oObj, ID.FromInteger(id));
oObj.ExitInterviewID = oExitInterview.ID;
ExitInterviewDA.Insert(tc, oObj);
}
tc.End();
return oExitInterview.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(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ExitInterviewDA.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
}
}
#endregion
}
#endregion
}