CEL_Payroll/Payroll.Service/Recruitement/Service/RecruitmentLettersService.cs

356 lines
15 KiB
C#
Raw Permalink Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
using Payroll.BO;
using Ease.CoreV35.Caching;
namespace Payroll.Service
{
#region RecruitmentLetters Service
[Serializable]
public class RecruitmentLettersService : ServiceTemplate, IRecruitmentLettersService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(RecruitmentLetters));
#endregion
public RecruitmentLettersService() { }
#region MapObject For RecruitmentLetters
private void MapObject(RecruitmentLetters oRecruitmentLetter, DataReader oReader)
{
base.SetObjectID(oRecruitmentLetter, oReader.GetID("RecruitmentLetterID"));
oRecruitmentLetter.CandidateID = oReader.GetID("CandidateID");
oRecruitmentLetter.ProcessID = oReader.GetID("ProcessID");
oRecruitmentLetter.AcceptOfferBefore = oReader.GetDateTime("AcceptOfferBefore").GetValueOrDefault(DateTime.MinValue);
oRecruitmentLetter.IssueOfferDate = oReader.GetDateTime("IssueOfferDate").GetValueOrDefault(DateTime.MinValue);
oRecruitmentLetter.AcceptOfferDate = oReader.GetDateTime("AcceptOfferDate").GetValueOrDefault(DateTime.MinValue);
oRecruitmentLetter.RejectOfferDate = oReader.GetDateTime("RejectOfferDate").GetValueOrDefault(DateTime.MinValue);
oRecruitmentLetter.RejectOfferReason = oReader.GetString("RejectOfferReason");
oRecruitmentLetter.OfferLetterCount = oReader.GetInt32("OfferLetterCount").GetValueOrDefault(0);
oRecruitmentLetter.OfferCreatedBy = oReader.GetID("OfferCreatedBy").IsUnassigned ? ID.FromInteger(0) : oReader.GetID("OfferCreatedBy");
oRecruitmentLetter.OfferCreatedDate = oReader.GetDateTime("OfferCreatedDate").GetValueOrDefault(DateTime.MinValue);
oRecruitmentLetter.GradeID = oReader.GetID("GradeID").IsUnassigned ? ID.FromInteger(0) : oReader.GetID("GradeID");
oRecruitmentLetter.BasicSalary = oReader.GetDouble("BasicSalary").GetValueOrDefault(0);
oRecruitmentLetter.DepartmentID = oReader.GetID("DepartmentID").IsUnassigned ? ID.FromInteger(0) : oReader.GetID("DepartmentID");
oRecruitmentLetter.LocationID = oReader.GetID("LocationID").IsUnassigned ? ID.FromInteger(0) : oReader.GetID("LocationID");
//oRecruitmentLetter.EmployeeID = oReader.GetID("EmployeeID").IsUnassigned ? ID.FromInteger(0) : oReader.GetID("EmployeeID");
oRecruitmentLetter.NoticePeriod = oReader.GetInt32("NoticePeriod").GetValueOrDefault(0);
oRecruitmentLetter.AppAcceptBefore = oReader.GetDateTime("AppAcceptBefore").GetValueOrDefault(DateTime.MinValue);
oRecruitmentLetter.IssueAppLetterDate = oReader.GetDateTime("IssueAppLetterDate").GetValueOrDefault(DateTime.MinValue);
oRecruitmentLetter.RejectAppLetterDate = oReader.GetDateTime("RejectAppLetterDate").GetValueOrDefault(DateTime.MinValue);
oRecruitmentLetter.RejectAppLetterReason = oReader.GetString("RejectAppLetterReason");
oRecruitmentLetter.CarEligible = oReader.GetBoolean("CarEligible").GetValueOrDefault(false);
oRecruitmentLetter.AppCreatedBy = oReader.GetID("AppCreatedBy").IsUnassigned ? ID.FromInteger(0) : oReader.GetID("AppCreatedBy");
oRecruitmentLetter.AppCreatedDate = oReader.GetDateTime("AppCreatedDate").GetValueOrDefault(DateTime.MinValue);
oRecruitmentLetter.AppLetterCount = oReader.GetInt32("AppLetterCount").GetValueOrDefault(0);
oRecruitmentLetter.JoiningLetter = oReader.GetBoolean("JoiningLetter").GetValueOrDefault(false);
oRecruitmentLetter.VendorMail = oReader.GetBoolean("VendorMail").GetValueOrDefault(false);
oRecruitmentLetter.WelcomeMail = oReader.GetBoolean("WelcomeMail").GetValueOrDefault(false);
oRecruitmentLetter.InductionRequest = oReader.GetBoolean("InductionRequest").GetValueOrDefault();
oRecruitmentLetter.Announcement = oReader.GetBoolean("Announcement").GetValueOrDefault(false);
oRecruitmentLetter.OtherLetters = oReader.GetBoolean("OtherLetters").GetValueOrDefault(false);
oRecruitmentLetter.OthersCount = oReader.GetInt32("OthersCount").GetValueOrDefault(0);
oRecruitmentLetter.OtherCreatedBy = oReader.GetID("OtherCreatedBy").IsUnassigned ? ID.FromInteger(0) : oReader.GetID("OtherCreatedBy");
oRecruitmentLetter.OtherCreateddate = oReader.GetDateTime("OtherCreateddate").GetValueOrDefault(DateTime.MinValue);
oRecruitmentLetter.JoiningBeforeDate = oReader.GetDateTime("JoiningBeforeDate").GetValueOrDefault(DateTime.MinValue);
oRecruitmentLetter.ConfirmJoiningDate = oReader.GetDateTime("ConfirmJoiningDate").GetValueOrDefault(DateTime.MinValue);
oRecruitmentLetter.CreatedBy = oReader.GetID("CreatedBy");
oRecruitmentLetter.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oRecruitmentLetter.ModifiedBy = oReader.GetID("ModifiedBy");
oRecruitmentLetter.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oRecruitmentLetter, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
RecruitmentLetters oRecruitmentLetter = new RecruitmentLetters();
MapObject(oRecruitmentLetter, oReader);
return oRecruitmentLetter as T;
}
protected RecruitmentLetters CreateObject(DataReader oReader)
{
RecruitmentLetters oRecruitmentLetter = new RecruitmentLetters();
MapObject(oRecruitmentLetter, oReader);
return oRecruitmentLetter;
}
#endregion
#region Service Implementation
public RecruitmentLetters Get(ID id)
{
RecruitmentLetters oRecruitmentLetter = new RecruitmentLetters();
#region Cache Header
oRecruitmentLetter = _cache["Get", id] as RecruitmentLetters;
if (oRecruitmentLetter != null)
return oRecruitmentLetter;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(RecruitmentLettersDA.Get(tc, id));
if (oreader.Read())
{
oRecruitmentLetter = this.CreateObject<RecruitmentLetters>(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(oRecruitmentLetter, "Get", id);
#endregion
return oRecruitmentLetter;
}
public RecruitmentLetters GetByCandidateID(ID nCandidateID)
{
RecruitmentLetters oRecruitmentLetter = new RecruitmentLetters();
#region Cache Header
oRecruitmentLetter = _cache["GetByCandidateID", nCandidateID] as RecruitmentLetters;
if (oRecruitmentLetter != null)
return oRecruitmentLetter;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(RecruitmentLettersDA.GetByCandidateID(tc, nCandidateID));
if (oreader.Read())
{
oRecruitmentLetter = this.CreateObject<RecruitmentLetters>(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(oRecruitmentLetter, "GetByCandidateID", nCandidateID);
#endregion
return oRecruitmentLetter;
}
public ObjectsTemplate<RecruitmentLetters> Get()
{
#region Cache Header
ObjectsTemplate<RecruitmentLetters> recruitmentLetters = _cache["Get"] as ObjectsTemplate<RecruitmentLetters>;
if (recruitmentLetters != null)
return recruitmentLetters;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(RecruitmentLettersDA.Get(tc));
recruitmentLetters = this.CreateObjects<RecruitmentLetters>(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(recruitmentLetters, "Get");
#endregion
return recruitmentLetters;
}
public ObjectsTemplate<RecruitmentLetters> GetByProcessID(ID nProcessID)
{
#region Cache Header
ObjectsTemplate<RecruitmentLetters> recruitmentLetters = _cache["GetByProcessID", nProcessID] as ObjectsTemplate<RecruitmentLetters>;
if (recruitmentLetters != null)
return recruitmentLetters;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(RecruitmentLettersDA.GetByProcessID(tc,nProcessID));
recruitmentLetters = this.CreateObjects<RecruitmentLetters>(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(recruitmentLetters, "GetByProcessID", nProcessID);
#endregion
return recruitmentLetters;
}
public ID Save(RecruitmentLetters oRecruitmentLetters,int CheckValue)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oRecruitmentLetters.IsNew)
{
int id = tc.GenerateID("RecruitmentLetters", "RecruitmentLetterID");
base.SetObjectID(oRecruitmentLetters, ID.FromInteger(id));
oRecruitmentLetters.OfferCreatedBy = oRecruitmentLetters.CreatedBy;
oRecruitmentLetters.OfferCreatedDate = oRecruitmentLetters.CreatedDate;
RecruitmentLettersDA.Insert(tc, oRecruitmentLetters);
}
else
{
if (CheckValue == 1)
{
oRecruitmentLetters.OfferCreatedBy = oRecruitmentLetters.CreatedBy;
oRecruitmentLetters.OfferCreatedDate = oRecruitmentLetters.CreatedDate;
}
else if (CheckValue == 2)
{
oRecruitmentLetters.AppCreatedBy = oRecruitmentLetters.CreatedBy;
oRecruitmentLetters.AppCreatedDate = oRecruitmentLetters.CreatedDate;
}
else
{
oRecruitmentLetters.OtherCreatedBy = oRecruitmentLetters.CreatedBy;
oRecruitmentLetters.OtherCreateddate = oRecruitmentLetters.CreatedDate;
}
RecruitmentLettersDA.Update(tc, oRecruitmentLetters);
}
return oRecruitmentLetters.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
finally
{
tc.End();
}
}
public void Delete(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
RecruitmentLettersDA.Delete(tc, id);
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
finally
{
tc.End();
}
}
public void Save(ObjectsTemplate<RecruitmentLetters> recruitmentLetters)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (recruitmentLetters.Count > 0)
{
foreach (RecruitmentLetters letterItem in recruitmentLetters)
{
if (letterItem.IsNew)
{
int id = tc.GenerateID("RecruitmentLetters", "RecruitmentLetterID");
base.SetObjectID(letterItem, ID.FromInteger(id));
RecruitmentLettersDA.Insert(tc, letterItem);
}
else
{
RecruitmentLettersDA.Update(tc, letterItem);
}
}
}
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
finally
{
tc.End();
}
}
#endregion
}
#endregion
}