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.Net.NetworkInformation; using static iTextSharp.text.pdf.AcroFields; namespace HRM.DA { #region RecruitmentLetters Service public class RecruitmentLettersService : ServiceTemplate, IRecruitmentLettersService { public RecruitmentLettersService() { } #region MapObject For RecruitmentLetters private void MapObject(RecruitmentLetters oRecruitmentLetter, DataReader oReader) { base.SetObjectID(oRecruitmentLetter, (oReader.GetInt32("RecruitmentLetterID").Value)); oRecruitmentLetter.CandidateID = oReader.GetInt32("CandidateID", 0); oRecruitmentLetter.RequisitionID = oReader.GetInt32("RequisitionID").Value; oRecruitmentLetter.ProcessID = oReader.GetInt32("ProcessID", 0); oRecruitmentLetter.AcceptOfferBefore = oReader.GetDateTime("AcceptOfferBefore"); oRecruitmentLetter.IssueOfferDate = oReader.GetDateTime("IssueOfferDate"); oRecruitmentLetter.AcceptOfferDate = oReader.GetDateTime("AcceptOfferDate"); oRecruitmentLetter.RejectOfferDate = oReader.GetDateTime("RejectOfferDate"); oRecruitmentLetter.RejectOfferReason = oReader.GetString("RejectOfferReason"); oRecruitmentLetter.OfferLetterCount = oReader.GetInt32("OfferLetterCount", 0); oRecruitmentLetter.OfferCreatedBy = (oReader.GetInt32("OfferCreatedBy", 0)); oRecruitmentLetter.OfferCreatedDate = oReader.GetDateTime("OfferCreatedDate"); oRecruitmentLetter.GradeID = oReader.GetInt32("GradeID", 0); oRecruitmentLetter.BasicSalary = oReader.GetDouble("BasicSalary").GetValueOrDefault(0); oRecruitmentLetter.DepartmentID = (oReader.GetInt32("DepartmentID", 0)); oRecruitmentLetter.LocationID = (oReader.GetInt32("LocationID", 0)); //oRecruitmentLetter.EmployeeID = oReader.GetID("EmployeeID").IsUnassigned ? (0) : oReader.GetID("EmployeeID"); oRecruitmentLetter.NoticePeriod = oReader.GetInt32("NoticePeriod").GetValueOrDefault(0); oRecruitmentLetter.AppAcceptBefore = oReader.GetDateTime("AppAcceptBefore"); oRecruitmentLetter.IssueAppLetterDate = oReader.GetDateTime("IssueAppLetterDate"); oRecruitmentLetter.RejectAppLetterDate = oReader.GetDateTime("RejectAppLetterDate"); oRecruitmentLetter.RejectAppLetterReason = oReader.GetString("RejectAppLetterReason"); oRecruitmentLetter.CarEligible = oReader.GetBoolean("CarEligible").GetValueOrDefault(false); oRecruitmentLetter.AppCreatedBy = (oReader.GetInt32("AppCreatedBy", 0)); 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.GetInt32("OtherCreatedBy", 0)); oRecruitmentLetter.OtherCreateddate = oReader.GetDateTime("OtherCreateddate", true, DateTime.MinValue); oRecruitmentLetter.JoiningDate = oReader.GetDateTime("JoiningDate", true, DateTime.MinValue); oRecruitmentLetter.JoiningBeforeDate = oReader.GetDateTime("JoiningBeforeDate", true, DateTime.MinValue); oRecruitmentLetter.ConfirmJoiningDate = oReader.GetDateTime("ConfirmJoiningDate", true, DateTime.MinValue); oRecruitmentLetter.CreatedBy = oReader.GetInt32("CreatedBy").Value; oRecruitmentLetter.CreatedDate = oReader.GetDateTime("CreationDate").Value; oRecruitmentLetter.ModifiedBy = oReader.GetInt32("ModifiedBy"); oRecruitmentLetter.ModifiedDate = oReader.GetDateTime("ModifiedDate"); oRecruitmentLetter.GrossSalary = oReader.GetDouble("GrossSalary").GetValueOrDefault(0); oRecruitmentLetter.JobLocation = oReader.GetString("JobLocation", true, null); oRecruitmentLetter.OfferLetterCreatedDate = oReader.GetDateTime("OfferLetterFileCreatedDate", true, DateTime.MinValue); oRecruitmentLetter.JoiningInformationLetterCreatedDate = oReader.GetDateTime("JoiningInformationLetterCreatedDate", true, DateTime.MinValue); oRecruitmentLetter.MailToLMLetterCreatedDate = oReader.GetDateTime("MailToLMLetterCreatedDate", true, DateTime.MinValue); oRecruitmentLetter.AppointmentLetterCreatedDate = oReader.GetDateTime("AppointmentLetterCreatedDate", true, DateTime.MinValue); oRecruitmentLetter.OfferLetterCreatedBy = oReader.GetInt32("OfferLetterFileCreatedBy", true, 0); oRecruitmentLetter.JoiningInformationLetterCreatedBy = oReader.GetInt32("JoiningInformationLetterCreatedBy", true, 0); oRecruitmentLetter.MailToLMLetterCreatedBy = oReader.GetInt32("MailToLMLetterCreatedBy", true, 0); oRecruitmentLetter.AppointmentLetterCreatedBy = oReader.GetInt32("AppointmentLetterCreatedBy", true, 0); this.SetObjectState(oRecruitmentLetter, Ease.Core.ObjectState.Saved); } protected override T CreateObject(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 Map JoiningPreparation Object private void MapJoiningPreparation(JoiningPreparation obRecStep, DataReader oReader) { SetObjectID(obRecStep, (oReader.GetInt32("JoiningPreparationID").Value)); obRecStep.RecruitmentLetterID = oReader.GetInt32("RecruitmentLetterID", true, 0); obRecStep.EmployeeInformationBankStatus = oReader.GetInt32("EMPLOYEEINFORMATIONBANKSTATUS", true, 0); obRecStep.JoiningReportDocumentStatus = oReader.GetInt32("JOININGREPORTDOCUMENTSTATUS", true, 0); obRecStep.ColorPhotoStatus = oReader.GetInt32("COLORPHOTOSTATUS", true, 0); obRecStep.ReleaseClearanceLetterStatus = oReader.GetInt32("RELEASECLEARANCELETTERSTATUS", true, 0); obRecStep.ExperienceCertificateLastOrganizationStatus = oReader.GetInt32("EXPERIENCECERTIFICATELASTORGANIZATIONSTATUS", true, 0); obRecStep.ExperienceCertificateStatus = oReader.GetInt32("EXPERIENCECERTIFICATESTATUS", true, 0); obRecStep.EducationalCertificateStatus = oReader.GetInt32("EDUCATIONALCERTIFICATESTATUS", true, 0); obRecStep.TrainingCertificateStatus = oReader.GetInt32("TRAININGCERTIFICATESTATUS", true, 0); obRecStep.NIDStatus = oReader.GetInt32("NIDSTATUS", true, 0); obRecStep.ETINStatus = oReader.GetInt32("ETINSTATUS", true, 0); obRecStep.HealthFitnessCertificateStatus = oReader.GetInt32("HEALTHFITNESSCERTIFICATESTATUS", true, 0); obRecStep.HealthInsuranceFormStatus = oReader.GetInt32("HEALTHINSURANCEFORMSTATUS", true, 0); obRecStep.BankAccountInformationStatus = oReader.GetInt32("BANKACCOUNTINFORMATIONSTATUS", true, 0); obRecStep.NomineeFormStatus = oReader.GetInt32("NOMINEEFORMSTATUS", true, 0); obRecStep.RecruitmentFeedbackFormStatus = oReader.GetInt32("RECRUITMENTFEEDBACKFORMSTATUS", true, 0); obRecStep.AcknowledgementFormStatus = oReader.GetInt32("ACKNOWLEDGEMENTFORMSTATUS", true, 0); obRecStep.EmployeeInformationBankRemarks = oReader.GetString("EMPLOYEEINFORMATIONBANKREMARKS", true, null); obRecStep.JoiningReportDocumentRemarks = oReader.GetString("JOININGREPORTDOCUMENTREMARKS", true, null); obRecStep.ColorPhotoRemarks = oReader.GetString("COLORPHOTOREMARKS", true, null); obRecStep.ReleaseClearanceLetterRemarks = oReader.GetString("RELEASECLEARANCELETTERREMARKS", true, null); obRecStep.ExperienceCertificateLastOrganizationRemarks = oReader.GetString("EXPERIENCECERTIFICATELASTORGANIZATIONREMARKS", true, null); obRecStep.ExperienceCertificateRemarks = oReader.GetString("EXPERIENCECERTIFICATEREMARKS", true, null); obRecStep.EducationalCertificateRemarks = oReader.GetString("EDUCATIONALCERTIFICATEREMARKS", true, null); obRecStep.TrainingCertificateRemarks = oReader.GetString("TRAININGCERTIFICATEREMARKS", true, null); obRecStep.NIDRemarks = oReader.GetString("NIDREMARKS", true, null); obRecStep.ETINRemarks = oReader.GetString("ETINREMARKS", true, null); obRecStep.HealthFitnessCertificateRemarks = oReader.GetString("HEALTHFITNESSCERTIFICATEREMARKS", true, null); obRecStep.HealthInsuranceFormRemarks = oReader.GetString("HEALTHINSURANCEFORMREMARKS", true, null); obRecStep.BankAccountInformationRemarks = oReader.GetString("BANKACCOUNTINFORMATIONREMARKS", true, null); obRecStep.NomineeFormRemarks = oReader.GetString("NOMINEEFORMREMARKS", true, null); obRecStep.RecruitmentFeedbackFormRemarks = oReader.GetString("RECRUITMENTFEEDBACKFORMREMARKS", true, null); obRecStep.AcknowledgementFormRemarks = oReader.GetString("ACKNOWLEDGEMENTFORMREMARKS", true, null); this.SetObjectState(obRecStep, ObjectState.Saved); } private List CreateJoiningPreparationObjects(DataReader oReader) { List allRecruSteps = new List(); while (oReader.Read()) { JoiningPreparation obReStep = new JoiningPreparation(); MapJoiningPreparation(obReStep, oReader); allRecruSteps.Add(obReStep); } return allRecruSteps; } #endregion #region Service Implementation public RecruitmentLetters Get(int id) { RecruitmentLetters oRecruitmentLetter = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(RecruitmentLettersDA.Get(tc, id)); if (oreader.Read()) { oRecruitmentLetter = this.CreateObject(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 oRecruitmentLetter; } public RecruitmentLetters GetByCandidateID(int nCandidateID) { RecruitmentLetters oRecruitmentLetter = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(RecruitmentLettersDA.GetByCandidateID(tc, nCandidateID)); if (oreader.Read()) { oRecruitmentLetter = this.CreateObject(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 oRecruitmentLetter; } public List Get() { List recruitmentLetters = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(RecruitmentLettersDA.Get(tc)); recruitmentLetters = this.CreateObjects(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 recruitmentLetters; } public List GetbyRequisitionID(int nProcessID) { List recruitmentLetters = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(RecruitmentLettersDA.GetbyRequisitionID(tc, nProcessID)); recruitmentLetters = this.CreateObjects(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 recruitmentLetters; } public List GetByProcessID(int nProcessID) { List recruitmentLetters = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(RecruitmentLettersDA.GetByProcessID(tc, nProcessID)); recruitmentLetters = this.CreateObjects(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 recruitmentLetters; } public int 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)); 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(int 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(List recruitmentLetters) { List saveditems = this.GetbyRequisitionID(recruitmentLetters[0].RequisitionID); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (recruitmentLetters.Count > 0) { foreach (RecruitmentLetters letterItem in recruitmentLetters) { var saveItem = saveditems.Find(x => x.RequisitionID == letterItem.RequisitionID && x.CandidateID == letterItem.CandidateID); InternalRecruitment position = new InternalRecruitmentService().Get(recruitmentLetters[0].RequisitionID); DateTime? acceptDate = letterItem.AcceptOfferDate; DateTime? rejectDate = letterItem.RejectOfferDate; if(acceptDate != null) { var status = "Offer Letter Accepted." + "Position: " + position.PositionName + " Date: " + position.PositionDate.ToString("dd-MM-yyyy"); CVDA.UpdateCandidateLastStatus(status, letterItem.CandidateID, tc); } else if(rejectDate != null) { var status = "Offer Letter Rejected." + "Position: " + position.PositionName + " Date: " + position.PositionDate.ToString("dd-MM-yyyy"); CVDA.UpdateCandidateLastStatus(status, letterItem.CandidateID, tc); } if (saveItem!= null) { letterItem.ID = saveItem.ID; } if (letterItem.IsNew) { int id = tc.GenerateID("RecruitmentLetters", "RecruitmentLetterID"); base.SetObjectID(letterItem, (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(); } } public void Save(TransactionContext tc, List recruitmentLetters) { List saveditems = this.GetbyRequisitionID(recruitmentLetters[0].RequisitionID); try { if (recruitmentLetters.Count > 0) { foreach (RecruitmentLetters letterItem in recruitmentLetters) { var saveItem = saveditems.Find(x => x.RequisitionID == letterItem.RequisitionID && x.CandidateID == letterItem.CandidateID); InternalRecruitment position = new InternalRecruitmentService().Get(recruitmentLetters[0].RequisitionID); DateTime? acceptDate = letterItem.AcceptOfferDate; DateTime? rejectDate = letterItem.RejectOfferDate; if (acceptDate != null) { var status = "Offer Letter Accepted." + "Position: " + position.PositionName + " Date: " + position.PositionDate.ToString("dd-MM-yyyy"); CVDA.UpdateCandidateLastStatus(status, letterItem.CandidateID, tc); } else if (rejectDate != null) { var status = "Offer Letter Rejected." + "Position: " + position.PositionName + " Date: " + position.PositionDate.ToString("dd-MM-yyyy"); CVDA.UpdateCandidateLastStatus(status, letterItem.CandidateID, tc); } if (saveItem != null) { letterItem.ID = saveItem.ID; } if (letterItem.IsNew) { int id = tc.GenerateID("RecruitmentLetters", "RecruitmentLetterID"); base.SetObjectID(letterItem, (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 } } #region JoiningPreparation public List GetJoiningPreparationbyRecruitmentLetterID(int rID) { List joiningPreparations = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(JoiningPreparationDA.getByRecruitmentLetterID(tc, rID)); joiningPreparations = CreateJoiningPreparationObjects(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 joiningPreparations; } public JoiningPreparation SaveJoiningPreparation(JoiningPreparation jp) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id = tc.GenerateID("JOININGPREPARATION", "JoiningPreparationID"); base.SetObjectID(jp, (id)); JoiningPreparationDA.DeleteJPbyRecruitmentLetterID((int)jp.RecruitmentLetterID, tc); JoiningPreparationDA.Insert(jp, tc); tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return jp; } #endregion #region Offer Letter Save public void SaveOfferLetter(string connectionString, RecruitmentLetters recruitmentLetter, string letterType) { TransactionContext tc = null; try { RecruitmentLettersDA.UpdateOfferLetterAttachment(connectionString, recruitmentLetter, letterType); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void SaveOfferLetter(RecruitmentLetters recruitmentLetter, string letterType) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); List recruitmentLetters = new List(); recruitmentLetters.Add(recruitmentLetter); this.Save(tc, recruitmentLetters); RecruitmentLettersDA.UpdateOfferLetterAttachment(tc, recruitmentLetter, letterType); 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 } #endregion }