EchoTex_Payroll/HRM.DA/Service/Recruitement/RecJobTrackingService.cs

278 lines
9.5 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Data;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core;
using System.Collections.Generic;
using Ease.Core.Utility;
using HRM.BO;
using System.IO;
using System.Linq;
using HRM.BO.Basic;
using NPOI.SS.Formula.Functions;
using Payroll.BO;
using static HRM.BO.RecJobTracking;
using Payroll.Service;
namespace HRM.DA
{
public class RecJobTrackingService : ServiceTemplate, IRecJobTrackingService
{
#region CV Object Mapping
private void MapCVObject(RecJobTracking obJobTracking, DataReader oReader)
{
this.SetObjectID(obJobTracking, oReader.GetInt32("RecJobTrackingID").Value);
obJobTracking.RecruitementID = oReader.GetInt32("RecruitementID", true, 0);
obJobTracking.RecruiterID = oReader.GetInt32("RecruiterID", true, 0);
obJobTracking.OnBoardDays = oReader.GetInt32("OnBoardDays", true, 0);
obJobTracking.OnBoardDate = (DateTime)oReader.GetDateTime("OnBoardDate").Value;
obJobTracking.TrackingStartDate = (DateTime)oReader.GetDateTime("TrackingStartDate").Value;
obJobTracking.JobPostingDate = (DateTime)oReader.GetDateTime("JobPostingDate").Value;
obJobTracking.ActualJobPostingDate = oReader.GetDateTime("ActualJobPostingDate").HasValue ? (DateTime)oReader.GetDateTime("ActualJobPostingDate").Value : null;
obJobTracking.CvCollectionDate = (DateTime)oReader.GetDateTime("CvCollectionDate").Value;
obJobTracking.ActualCvCollectionDate = oReader.GetDateTime("ActualCvCollectionDate").HasValue ? (DateTime)oReader.GetDateTime("ActualCvCollectionDate").Value : null;
obJobTracking.InterviewStartDate = (DateTime)oReader.GetDateTime("InterviewStartDate").Value;
obJobTracking.ActualInterviewStartDate = oReader.GetDateTime("ActualInterviewStartDate").HasValue ? (DateTime)oReader.GetDateTime("ActualInterviewStartDate").Value : null;
obJobTracking.InterviewEndDate = (DateTime)oReader.GetDateTime("InterviewEndDate").Value;
obJobTracking.ActualInterviewEndDate = oReader.GetDateTime("ActualInterviewEndDate").HasValue ? (DateTime)oReader.GetDateTime("ActualInterviewEndDate").Value : null;
obJobTracking.OfferLetterSendDate = (DateTime)oReader.GetDateTime("OfferLetterSendDate").Value;
obJobTracking.ActualOfferLetterSendDate = oReader.GetDateTime("ActualOfferLetterSendDate").HasValue ? (DateTime)oReader.GetDateTime("ActualOfferLetterSendDate").Value : null;
obJobTracking.JoiningDate = (DateTime)oReader.GetDateTime("JoiningDate").Value;
obJobTracking.ActualJoiningDate = oReader.GetDateTime("ActualJoiningDate").HasValue ? (DateTime)oReader.GetDateTime("ActualJoiningDate").Value : null;
if (oReader.GetDateTime("CreatedDate") == null)
{
obJobTracking.CreatedDate = DateTime.MinValue;
}
else
{
obJobTracking.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
}
if (oReader.GetDateTime("ModifiedDate") == null)
{
obJobTracking.ModifiedDate = DateTime.MinValue;
}
else
{
obJobTracking.ModifiedDate = oReader.GetDateTime("ModifiedDate").Value;
}
this.SetObjectState(obJobTracking, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
RecJobTracking obJobTracking = new RecJobTracking();
MapCVObject(obJobTracking, oReader);
return obJobTracking as T;
}
#endregion
#region Service Implementation
#region Insert(CV obCv)
public void Save(RecJobTracking obJobTracking)
{
TransactionContext tc = null;
int oID = 0;
try
{
tc = TransactionContext.Begin(true);
if (obJobTracking.IsNew)
{
int id = tc.GenerateID("RecJobTracking", "RecJobTrackingID");
oID = (id);
base.SetObjectID(obJobTracking, (id));
obJobTracking.ActualJobPostingDate = DateTime.Now;
RecJobTrackingDA.Insert(obJobTracking, tc);
RecJobTrackingDA.UpdateactualJobPosting(tc, oID);
InternalRecruitmentDA.UpdateRequisitionStatus(tc, obJobTracking.RecruitementID, EnumOnBoradStatus.CVPosting);
}
else
{
RecJobTrackingDA.Update(obJobTracking, tc);
}
tc.End();
}
catch (Exception ex)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(ex);
throw new ServiceException(ex.Message, ex);
#endregion
}
}
#endregion
#region Get()
public List<RecJobTracking> Get()
{
List<RecJobTracking> allRecJobTracking = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
DataReader oreader = new DataReader(RecJobTrackingDA.Get(tc));
allRecJobTracking = this.CreateObjects<RecJobTracking>(oreader);
oreader.Close();
tc.End();
}
catch (Exception ex)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(ex);
throw new ServiceException(ex.Message, ex);
#endregion
}
return allRecJobTracking;
}
#endregion
#region Get(int cVID)
public RecJobTracking Get(int ID)
{
RecJobTracking jobTracking = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
DataReader oreader = new DataReader(RecJobTrackingDA.GetByID(ID, tc));
if (oreader.Read())
{
jobTracking = this.CreateObject<RecJobTracking>(oreader);
}
oreader.Close();
tc.End();
}
catch (Exception ex)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(ex);
throw new ServiceException(ex.Message, ex);
#endregion
}
return jobTracking;
}
public RecJobTracking GetByRecruitmentId(int ID)
{
RecJobTracking jobTracking = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
DataReader oreader = new DataReader(RecJobTrackingDA.GetByRecruimentId(ID, tc));
if (oreader.Read())
{
jobTracking = this.CreateObject<RecJobTracking>(oreader);
}
oreader.Close();
tc.End();
}
catch (Exception ex)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(ex);
throw new ServiceException(ex.Message, ex);
#endregion
}
return jobTracking;
}
public RecJobTracking GetByRecruitmentId(TransactionContext tc, int ID)
{
RecJobTracking jobTracking = null;
try
{
DataReader oreader = new DataReader(RecJobTrackingDA.GetByRecruimentId(ID, tc));
if (oreader.Read())
{
jobTracking = this.CreateObject<RecJobTracking>(oreader);
}
oreader.Close();
}
catch (Exception ex)
{
#region Handle Exception
ExceptionLog.Write(ex);
throw new ServiceException(ex.Message, ex);
#endregion
}
return jobTracking;
}
public void UpdateActualDate(int recruitmentId,DateTime? joiningDate)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
var recJobTracking = new RecJobTrackingService().GetByRecruitmentId(tc, recruitmentId);
if (recJobTracking != null)
{
if (recJobTracking.ActualOfferLetterSendDate == null)
{
RecJobTrackingDA.UpdateActualOfferLetterSendDate(tc, recruitmentId);
}
if (recJobTracking.ActualJoiningDate == null && joiningDate != null)
{
RecJobTrackingDA.UpdateActualJoiningDate(tc, recruitmentId);
}
}
tc.End();
}
catch (Exception ex)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(ex);
throw new ServiceException(ex.Message, ex);
#endregion
}
}
#endregion
#endregion
}
}