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 System.Reflection; namespace HRM.DA { public class ErCVService : ServiceTemplate, IErCVService { #region CV Object Mapping private void MapCVObject(ErCV obCv, DataReader oReader) { this.SetObjectID(obCv, oReader.GetInt32("CVID").Value); obCv.Name = oReader.GetString("Name") != null ? oReader.GetString("Name") : string.Empty; obCv.FirstName = oReader.GetString("FirstName") != null ? oReader.GetString("FirstName") : string.Empty; obCv.LastName = oReader.GetString("LastName") != null ? oReader.GetString("LastName") : string.Empty; obCv.Email = oReader.GetString("Email") != null ? oReader.GetString("Email") : string.Empty; obCv.Mobile = oReader.GetString("Mobile") != null ? oReader.GetString("Mobile") : string.Empty; obCv.Designation = oReader.GetString("Designation", true, null); obCv.PresentAddress = oReader.GetString("PresentAddress", true, null); obCv.PermanentAddress = oReader.GetString("PermanentAddress", true, null); obCv.Gender = oReader.GetString("Gender") != null ? (EnumGender)oReader.GetInt32("Gender").Value : EnumGender.None; obCv.MaritalStatus = oReader.GetString("MaritalStatus") != null ? (EnumMaritalStatus)oReader.GetInt32("MaritalStatus").Value : EnumMaritalStatus.None; obCv.ReligionID = oReader.GetInt32("ReligionID", true, 0); obCv.PositionID = oReader.GetInt32("PositionID", true, 0); obCv.CandidateID = oReader.GetInt32("CandidateID", true, 0); obCv.SortStatus = oReader.GetString("SortStatus", true, null); obCv.UserID = oReader.GetInt32("UserID", true, 0); obCv.PresentAddress = oReader.GetString("PresentAddress", true, null); obCv.PermanentAddress = oReader.GetString("PermanentAddress", true, null); // obCv.PositionStatus = (EnumOnBoradStatus)oReader.GetInt32("ONBOARDSTATUS", true, 1); if (oReader.GetDateTime("CreationDate") == null) { obCv.CreatedDate = DateTime.MinValue; } else { obCv.CreatedDate = oReader.GetDateTime("CreationDate").Value; } if (oReader.GetDateTime("ModificationDate") == null) { obCv.ModifiedDate = DateTime.MinValue; } else { obCv.ModifiedDate = oReader.GetDateTime("ModificationDate").Value; } this.SetObjectState(obCv, ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { ErCV obCv = new ErCV(); MapCVObject(obCv, oReader); return obCv as T; } #endregion #region Experience Object Mapping private void MapExperience(ErCVExperience obExperience, DataReader oReader) { SetObjectID(obExperience, (oReader.GetInt32("CVExperienceID").Value)); obExperience.Employeer = oReader.GetString("Employeer") != null ? oReader.GetString("Employeer") : string.Empty; obExperience.ContactPerson = oReader.GetString("ContactPerson") != null ? oReader.GetString("ContactPerson") : string.Empty; obExperience.Address = oReader.GetString("Address") != null ? oReader.GetString("Address") : string.Empty; obExperience.Industry = oReader.GetString("Industry") != null ? oReader.GetString("Industry") : string.Empty; obExperience.Designation = oReader.GetString("Designation") != null ? oReader.GetString("Designation") : string.Empty; obExperience.FromDate = oReader.GetString("FromDate") != null ? oReader.GetDateTime("FromDate").Value : DateTime.MinValue; obExperience.ToDate = oReader.GetString("ToDate") != null ? oReader.GetDateTime("ToDate").Value : DateTime.MinValue; obExperience.Telephone = oReader.GetString("Telephone") != null ? oReader.GetString("Telephone") : string.Empty; obExperience.RoleDefination = oReader.GetString("RoleDefination") != null ? oReader.GetString("RoleDefination") : string.Empty; obExperience.Mobile = oReader.GetString("Mobile") != null ? oReader.GetString("Mobile") : string.Empty; obExperience.CVID = oReader.GetString("CVID") != null ? oReader.GetInt32("CVID").Value : 0; this.SetObjectState(obExperience, ObjectState.Saved); } private List CreateExperienceObjects(DataReader oReader) { List allExperiences = new List(); while (oReader.Read()) { ErCVExperience obExp = new ErCVExperience(); MapExperience(obExp, oReader); allExperiences.Add(obExp); } return allExperiences; } #endregion #region CVReference Object Mapping private void MapReference(ErCVReference obExperience, DataReader oReader) { SetObjectID(obExperience, (oReader.GetInt32("CVReferenceID").Value)); obExperience.Name = oReader.GetString("Name") != null ? oReader.GetString("Name") : string.Empty; obExperience.Occupation = oReader.GetString("Occupation") != null ? oReader.GetString("Occupation") : string.Empty; obExperience.Relation = oReader.GetString("Relation") != null ? oReader.GetString("Relation") : string.Empty; obExperience.Address = oReader.GetString("Address") != null ? oReader.GetString("Address") : string.Empty; obExperience.Email = oReader.GetString("Email") != null ? oReader.GetString("Email") : string.Empty; obExperience.Telephone = oReader.GetString("Telephone") != null ? oReader.GetString("Telephone") : string.Empty; obExperience.Mobile = oReader.GetString("Mobile") != null ? oReader.GetString("Mobile") : string.Empty; obExperience.CVID = oReader.GetString("CVID") != null ? oReader.GetInt32("CVID").Value : 0; this.SetObjectState(obExperience, ObjectState.Saved); } private List CreateReferenceObjects(DataReader oReader) { List allExperiences = new List(); while (oReader.Read()) { ErCVReference obExp = new ErCVReference(); MapReference(obExp, oReader); allExperiences.Add(obExp); } return allExperiences; } #endregion #region Map ReferredBy Object private void MapReferredBy(ReferredBy obReferredBy, DataReader oReader) { SetObjectID(obReferredBy, (oReader.GetInt32("ReferredByID").Value)); obReferredBy.CvId = (oReader.GetInt32("CvId").Value); obReferredBy.Name = oReader.GetString("Name"); obReferredBy.OtherDetail = oReader.GetString("OtherDetail"); obReferredBy.ReferredBY = (EnumReferredBy)oReader.GetInt32("ReferredBy"); this.SetObjectState(obReferredBy, ObjectState.Saved); } private List CreateReferredByObjects(DataReader oReader) { List allobRefs = new List(); while (oReader.Read()) { ReferredBy obRef = new ReferredBy(); MapReferredBy(obRef, oReader); allobRefs.Add(obRef); } return allobRefs; } #endregion #region Map CVOrg Object private void MapCVOrg(CVOrg obCVOrg, DataReader oReader) { SetObjectID(obCVOrg, (oReader.GetInt32("CVOrgID").Value)); obCVOrg.CvID = oReader.GetInt32("CVID", 0); obCVOrg.DesignationID = oReader.GetInt32("DesignationID", 0); obCVOrg.OrganizationId = oReader.GetInt32("OrganizationID", 0); obCVOrg.CVOrgType = (EnumCVOrgType)oReader.GetInt32("CVOrgType"); this.SetObjectState(obCVOrg, ObjectState.Saved); } private List CreateCVOrgObjects(DataReader oReader) { List allobCVOrgs = new List(); while (oReader.Read()) { CVOrg obCVOrg = new CVOrg(); MapCVOrg(obCVOrg, oReader); allobCVOrgs.Add(obCVOrg); } return allobCVOrgs; } #endregion #region Map EductionalQualification private void MapEductionalQualification(ErCVEducation obEductionalQualification, DataReader oReader) { SetObjectID(obEductionalQualification, (oReader.GetInt32("CVEducationID").Value)); obEductionalQualification.DegreeTitleID = oReader.GetInt32("DegreeTitleID", 0); obEductionalQualification.DisciplineID = oReader.GetInt32("DisciplineIID", 0); obEductionalQualification.BoardID = oReader.GetInt32("BoardID", 0); obEductionalQualification.PassingYear = oReader.GetString("PassingYear") != null ? oReader.GetString("PassingYear") : string.Empty; obEductionalQualification.ResultID = oReader.GetInt32("ResultID", 0); obEductionalQualification.CGPA = oReader.GetString("CGPA") != null ? oReader.GetString("CGPA") : string.Empty; obEductionalQualification.OutOF = oReader.GetString("OutOF") != null ? oReader.GetString("OutOF") : string.Empty; obEductionalQualification.IsHighest = oReader.GetBoolean("IsHighest").Value; obEductionalQualification.InstituteName = oReader.GetString("InstituteName") != null ? oReader.GetString("InstituteName") : string.Empty; obEductionalQualification.CVID = oReader.GetInt32("CVID", 0); obEductionalQualification.DegreeTitle = oReader.GetString("ExamTitle") != null ? oReader.GetString("ExamTitle") : string.Empty; obEductionalQualification.Concentration = oReader.GetString("Concentration") != null ? oReader.GetString("Concentration") : string.Empty; obEductionalQualification.Duration = oReader.GetString("Duration") != null ? oReader.GetString("Duration") : string.Empty; obEductionalQualification.Achievement = oReader.GetString("Achievement") != null ? oReader.GetString("Achievement") : string.Empty; this.SetObjectState(obEductionalQualification, ObjectState.Saved); } private List CreateEductionalQualificationObjects(DataReader oReader) { List allQualfs = new List(); while (oReader.Read()) { ErCVEducation obQuef = new ErCVEducation(); MapEductionalQualification(obQuef, oReader); allQualfs.Add(obQuef); } return allQualfs; } #endregion #region Map Training private void MapErCVTraining(ErCVTraining obErCVTraining, DataReader oReader) { SetObjectID(obErCVTraining, (oReader.GetInt32("ERCVTRAININGID").Value)); obErCVTraining.Name = oReader.GetString("Name", null); obErCVTraining.Description = oReader.GetString("Description", null); obErCVTraining.Country = oReader.GetString("Country", null); obErCVTraining.TrainingTypeID = oReader.GetInt32("TrainingTypeID", 0); obErCVTraining.NatureOfTrainingID = oReader.GetInt32("NatureOfTrainingID", 0); obErCVTraining.InstitutionID = oReader.GetString("INSTITUTIONID") != null ? oReader.GetInt32("INSTITUTIONID").Value :0; obErCVTraining.Achievement = oReader.GetString("Achievement",true, null); obErCVTraining.Place = oReader.GetString("TRAININGPLACE", true, null); obErCVTraining.FromDate = oReader.GetString("FromDate") != null ? oReader.GetDateTime("FromDate").Value : DateTime.MinValue; obErCVTraining.ToDate = oReader.GetString("ToDate") != null ? oReader.GetDateTime("ToDate").Value : DateTime.MinValue; obErCVTraining.CVID = oReader.GetInt32("CVID", 0); obErCVTraining.Days = oReader.GetString("Days",true, null); obErCVTraining.Hours = oReader.GetString("Hours", true, null); obErCVTraining.CountryID = oReader.GetString("Country") != null ? oReader.GetInt32("Country").Value : 0; obErCVTraining.InstituteName = oReader.GetString("InstituteName") != null ? oReader.GetString("InstituteName") : string.Empty; this.SetObjectState(obErCVTraining, ObjectState.Saved); } private List CreateErCVTrainingObjects(DataReader oReader) { List allTraining = new List(); while (oReader.Read()) { ErCVTraining obQuef = new ErCVTraining(); MapErCVTraining(obQuef, oReader); allTraining.Add(obQuef); } return allTraining; } #endregion #region CVAttachment protected List CreateirFileAttachmentObjects(DataReader oReader) { List oIRFileAttachments = new List(); while (oReader.Read()) { FileAttachment oIRFileAtachment = new FileAttachment(); MapIRFileAttachmentObject(oIRFileAtachment, oReader); oIRFileAttachments.Add(oIRFileAtachment); } return oIRFileAttachments; } private void MapIRFileAttachmentObject(FileAttachment oIRFileAttachment, DataReader oReader) { base.SetObjectID(oIRFileAttachment, (oReader.GetInt32("FILEATTACHMENTID").Value)); oIRFileAttachment.ReferenceID = oReader.GetInt32("ReferenceID", 0); oIRFileAttachment.FileAsByteArray = oReader.GetLob("FileData"); oIRFileAttachment.OriginalFileName = oReader.GetString("OriginalFileName"); oIRFileAttachment.FileType = (EnumFileType)oReader.GetInt32("FileType").GetValueOrDefault(); this.SetObjectState(oIRFileAttachment, Ease.Core.ObjectState.Saved); } //private List MapIRFileAttachmentObjects(DataReader oReader) //{ // List FileAttachment = new List(); // base.SetObjectID(oIRFileAttachment, (oReader.GetInt32("FILEATTACHMENTID").Value)); // oIRFileAttachment.ReferenceID = oReader.GetInt32("ReferenceID", 0); // oIRFileAttachment.FileAsByteArray = oReader.GetLob("FileData"); // oIRFileAttachment.OriginalFileName = oReader.GetString("OriginalFileName"); // oIRFileAttachment.FileType = (EnumFileType)oReader.GetInt32("FileType").GetValueOrDefault(); // this.SetObjectState(oIRFileAttachment, Ease.Core.ObjectState.Saved); //} #endregion #region Service Implementation #region GenerateTrackNo() public int GenerateTrackNo() { TransactionContext tc = null; int id; try { tc = TransactionContext.Begin(true); //id = tc.GenerateID("CVMain", "TrackNo"); id = tc.GenerateID("CVMain", "CvID"); tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return id; } #endregion #region Delete(CV obCv) public void Delete(ErCV obCv) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); #region Delete Experience ExperienceDA.Delete(obCv.ID, tc); #endregion #region Delete Reference CVReferenceDA.Delete(obCv.ID, tc); #endregion #region Delete Education CVEducationDA.Delete(obCv.ID, tc); #endregion #region Delete Attachment FileAttachmentDA.Delete(tc, obCv.ID, EnumFileType.ErCV); #endregion #region Delete CV CVDA.Delete(obCv.ID, tc); #endregion tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } } public void DeleteCVRecuirtmemt(ErCV obCv) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); #region Delete Experience ExperienceDA.Delete(obCv.ID, tc); #endregion #region Delete Reference CVReferenceDA.Delete(obCv.ID, tc); #endregion #region Delete Education CVEducationDA.Delete(obCv.ID, tc); #endregion #region Delete Attachment FileAttachmentDA.Delete(tc, obCv.ID, EnumFileType.ErCV); #endregion #region Delete CV CVDA.Delete(obCv.ID, tc); #endregion //#region Delete Candidate //CandidateDA.DeleteCVCandidate(tc, obCv.ID); //#endregion tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } } #endregion public List SaveCVs(List cvs, string connectionString) { List newItemList = new List(); List candidates = new List(); List idList = new List(); TransactionContext tc = null; int positionID = 0; try { tc = TransactionContext.Begin(true); foreach (var obCv in cvs) { positionID = obCv.PositionID; int oID = 0; if (obCv.IsNew) { int id = tc.GenerateID("CV", "CvID"); oID = (id); base.SetObjectID(obCv, (id)); //CVDA.InsertCVBase(obCv, tc); } else { oID = obCv.ID; //CVDA.UpdateCVBase(obCv, tc); } if (obCv.AllExperiences != null && obCv.AllExperiences.Count > 0) { ExperienceDA.DeleteByCvId(oID, tc); foreach (ErCVExperience exprItem in obCv.AllExperiences) { int id = tc.GenerateID("CVExperience", "CVExperienceID"); exprItem.CVID = oID; base.SetObjectID(exprItem, (id)); //ExperienceDA.InsertExperience(exprItem, tc); } } if (obCv.AllEduQualifications != null && obCv.AllEduQualifications.Count > 0) { CVEducationDA.DeleteByCvId(oID, tc); foreach (ErCVEducation eduItem in obCv.AllEduQualifications) { int id = tc.GenerateID("CVEducation", "CVEducationID"); eduItem.CVID = oID; base.SetObjectID(eduItem, (id)); //CVEducationDA.InsertEductionalQualification(eduItem, tc); } } if (obCv.CVReferences != null && obCv.CVReferences.Count > 0) { CVReferenceDA.DeleteByCvId(oID, tc); foreach (ErCVReference oItem in obCv.CVReferences) { int id = tc.GenerateID("CVReference", "CVReferenceID"); oItem.CVID = oID; base.SetObjectID(oItem, (id)); //CVReferenceDA.Insert(oItem, tc); } } CVDA.DeleteAttachment(tc, obCv.ID, EnumFileType.ErCV); var candidate = new Candidate(); candidate.CvID = oID; candidate.ProcessId = obCv.PositionID; candidate.IsSelected = false; candidate.IsEmployee = false; candidate.StartDate = new DateTime(); candidates.Add(candidate); idList.Add(obCv.ID); } if (candidates != null && candidates.Count > 0) { new CandidateService().SaveMultipleCandidates(tc, candidates); } tc.End(); foreach (var item in cvs) { if (item.IRFileAttacments != null && item.IRFileAttacments.Count > 0) { foreach (var uploadfile in item.IRFileAttacments) { if (uploadfile.ID > 0 && uploadfile.FileTobase64 != null) { byte[] newBytes = Convert.FromBase64String(uploadfile.FileTobase64); uploadfile.FileAsByteArray = newBytes; uploadfile.ReferenceID = item.ID; uploadfile.FileType = EnumFileType.ErCV; FileAttachmentDA.Insert(uploadfile, connectionString); } else { FileStream stream = new FileStream(uploadfile.FilePath, FileMode.Open, FileAccess.Read); BinaryReader reader = new BinaryReader(stream); byte[] buff = reader.ReadBytes((int)stream.Length); reader.Close(); stream.Close(); uploadfile.FileAsByteArray = buff; uploadfile.ReferenceID = item.ID; uploadfile.FileType = EnumFileType.ErCV; FileAttachmentDA.Insert(uploadfile, connectionString); } } } } //if (positionID > 0) //{ // CVDA.UpdateRequisitionStatus(positionID, EnumOnBoradStatus.CVCollection, tc); //} // newItemList = GetCVByIDs(String.Join(",", idList)); } catch (Exception ex) { if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); } return newItemList; } #region Insert(CV obCv) public void Save(ErCV obCv, string connectionString) { TransactionContext tc = null; int oID = 0; try { tc = TransactionContext.Begin(true); if (obCv.IsNew) { int id = tc.GenerateID("ERCV", "CvID"); oID = (id); base.SetObjectID(obCv, (id)); ErCVDA.InsertErCVBase(obCv, tc); } else { oID = obCv.ID; ErCVDA.UpdateCVBase(obCv, tc); } if (obCv.AllExperiences != null && obCv.AllExperiences.Count > 0) { ErCVExperienceDA.DeleteByCvId(oID, tc); foreach (ErCVExperience exprItem in obCv.AllExperiences) { int id = tc.GenerateID("ERCVExperience", "CVExperienceID"); exprItem.CVID = oID; base.SetObjectID(exprItem, (id)); ErCVExperienceDA.InsertErcvExperience(exprItem, tc); } } if (obCv.AllEduQualifications != null && obCv.AllEduQualifications.Count > 0) { ErCvEducationDA.DeleteByCvId(oID, tc); foreach (ErCVEducation eduItem in obCv.AllEduQualifications) { int id = tc.GenerateID("ERCVEducation", "CVEducationID"); eduItem.CVID = oID; base.SetObjectID(eduItem, (id)); ErCvEducationDA.InsertErCVEducation(eduItem, tc); } } if (obCv.CVReferences != null && obCv.CVReferences.Count > 0) { ErCVReferenceDA.DeleteByCvId(oID, tc); foreach (ErCVReference oItem in obCv.CVReferences) { int id = tc.GenerateID("ERCVREFERENCE", "CVReferenceID"); oItem.CVID = oID; base.SetObjectID(oItem, (id)); ErCVReferenceDA.Insert(oItem, tc); } } if (obCv.CVTrainings != null && obCv.CVTrainings.Count > 0) { ErCVTrainingDA.DeleteByCvId(oID, tc); foreach (ErCVTraining oItem in obCv.CVTrainings) { int id = tc.GenerateID("ERCVTRAINING", "ERCVTRAININGID"); oItem.CVID = oID; base.SetObjectID(oItem, (id)); ErCVTrainingDA.Insert(oItem, tc); } } ErJobUserDA.UpdateIsCvCompleted(tc, obCv.UserID); ErCVDA.DeleteAttachment(tc, obCv.ID, EnumFileType.ErCVProfilePhoto); if(obCv.IRFileAttacments != null && obCv.IRFileAttacments.Count > 0) { foreach (FileAttachment item in obCv.IRFileAttacments) { if(item.FileType == EnumFileType.ErCV) { ErCVDA.DeleteAttachment(tc, obCv.ID, EnumFileType.ErCV); } } } // CVDA.UpdateCVFromErecruitmentPortal(obCv.PositionID, obCv.ID, tc); tc.End(); if (obCv.ErCVProfilePhoto != null) { if(obCv.ErCVProfilePhoto.FileAsByteArray != null) { obCv.ErCVProfilePhoto.ReferenceID = oID; obCv.ErCVProfilePhoto.FileType = EnumFileType.ErCVProfilePhoto; obCv.ErCVProfilePhoto.RefchildID = null; FileAttachmentDA.Insert(obCv.ErCVProfilePhoto, connectionString); } } if (obCv.IRFileAttacments != null && obCv.IRFileAttacments.Count > 0) { foreach (FileAttachment item in obCv.IRFileAttacments) { if (item != null) { if (item.ID > 0 && item.PreviousFileTobase64 != null) { byte[] newBytes = Convert.FromBase64String(item.PreviousFileTobase64); item.FileAsByteArray = newBytes; item.ReferenceID = oID; item.RefchildID = null; item.FileType = EnumFileType.ErCV; FileAttachmentDA.Insert(item, connectionString); } else { item.ReferenceID = oID; item.FileType = EnumFileType.ErCV; item.RefchildID = null; FileAttachmentDA.Insert(item, connectionString); } } } } //List allCVs = null; //allCVs = GetByCvSearch(null, obCv.Email, null); //if(allCVs != null && allCVs.Count > 0) //{ // tc = TransactionContext.Begin(true); // CVDA.UpdateCVFromErecruitmentPortal(allCVs[0].ID, obCv.ID, tc); // tc.End(); //} //else //{ // CV cv = new CV(); // cv.Name= obCv.Name; // cv.FirstName = obCv.FirstName; // cv.LastName = obCv.LastName; // cv.Mobile = obCv.Mobile; // cv.Email = obCv.Email; // cv.PositionID = obCv.PositionID; // cv.ErCvID = obCv.ID; // tc = TransactionContext.Begin(true); // CVDA.InsertCVBase(cv,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 /// /// //For cv collection module /// /// public void SaveCVSort(List Items) { TransactionContext tc = null; try { int RequisitionID = 0; tc = TransactionContext.Begin(true); foreach (var obCvSort in Items) { RequisitionID = obCvSort.RequisitionID; int oID = 0; if (obCvSort.IsNew) { int id = tc.GenerateID("CVSort", "CVSORTID"); oID = (id); base.SetObjectID(obCvSort, (id)); //CVDA.InsertCVSort(obCvSort, tc); } else { oID = obCvSort.ID; //CVDA.UpdateCVSort(obCvSort, tc); } } if (RequisitionID > 0) { CVDA.UpdateRequisitionStatus(RequisitionID, EnumOnBoradStatus.CVCollection, tc); } tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } } #region Insert(CV obCv) public void SaveUserCVSort(ErUserCvSort obCv) { TransactionContext tc = null; int oID = 0; try { tc = TransactionContext.Begin(true); if (obCv.IsNew) { int id = tc.GenerateID("UserCvSort", "USERCVSORTID"); oID = (id); base.SetObjectID(obCv, (id)); // CVDA.InsertUserCvSort(obCv, tc); } //CVDA.UpdateCVCandidate(obCv, tc); //CVDA.UpdateCandidate(obCv, tc); tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } } #region GetReferredBy(int cVID) public List GetReferredBy(int cVID) { List allRefs = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(CVDA.GetReferredBy(cVID, tc)); allRefs = this.CreateReferredByObjects(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 allRefs; } #endregion #region GetCVOrgByID(int cVID) public List GetCVOrgByID(int cVID) { List allCVOrgs = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(CVDA.GetCVOrgByID(cVID, tc)); allCVOrgs = this.CreateCVOrgObjects(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 allCVOrgs; } #endregion #region GetEducationQualifications(int cVID) public List GetEducationQualifications(int cVID) { List allEduQuals = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(CVDA.GetEducationQualifications(cVID, tc)); allEduQuals = this.CreateEductionalQualificationObjects(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 allEduQuals; } #endregion #region GetExperiences(int cVID) public List GetExperiences(int cVID) { List allExps = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(CVDA.GetExperiences(cVID, tc)); allExps = this.CreateExperienceObjects(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 allExps; } #endregion #region Get() public List Get() { List allCVs = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(CVDA.Get(tc)); allCVs = this.CreateObjects(oreader); oreader.Close(); foreach (ErCV cv in allCVs) { if (cv != null) { cv.AllExperiences = GetAllExp(tc, cv.ID); cv.AllEduQualifications = GetAllEducations(tc, cv.ID); if (cv.AllEduQualifications != null && cv.AllEduQualifications.Count > 0) { foreach (ErCVEducation item in cv.AllEduQualifications) { item.EducationLevels = new EducationLevelService().GetByID(tc, item.DegreeTitleID); item.Disciplines = new DisciplineService().GetByID(tc, item.DisciplineID); } } cv.CVReferences = GetAllReferences(tc, cv.ID); cv.IRFileAttacments = GetAllAttachments(tc, cv.ID, EnumFileType.ErCV); } } tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return allCVs; } public List getAllOnlyCV() { List allCVs = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(CVDA.Get(tc)); allCVs = this.CreateObjects(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 allCVs; } public List GetByCvSearch(string name, string email, string mobile) { List allCVs = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(CVDA.GetByCvSearch(tc, name, email, mobile)); allCVs = this.CreateObjects(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 allCVs; } #endregion #region Get(int cVID) public ErCV Get(int cVID) { ErCV cv = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(ErCVDA.Get(cVID, tc)); if (oreader.Read()) { cv = this.CreateObject(oreader); } oreader.Close(); if (cv != null) { cv.AllExperiences = GetAllExp(tc, cv.ID); cv.AllEduQualifications = GetAllEducations(tc, cv.ID); if (cv.AllEduQualifications != null && cv.AllEduQualifications.Count > 0) { foreach (ErCVEducation item in cv.AllEduQualifications) { item.EducationLevels = new EducationLevelService().GetByID(tc, item.DegreeTitleID); item.Disciplines = new DisciplineService().GetByID(tc, item.DisciplineID); } } cv.CVReferences = GetAllReferences(tc, cv.ID); cv.IRFileAttacments = GetAllAttachments(tc, cv.ID, EnumFileType.ErCV); } tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return cv; } public ErCV GetErCvByUserID(int userId) { ErCV cv = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(ErCVDA.GetByUserId(userId, tc)); if (oreader.Read()) { cv = this.CreateObject(oreader); } oreader.Close(); if (cv != null) { cv.AllExperiences = GetAllExp(tc, cv.ID); cv.AllEduQualifications = GetAllEducations(tc, cv.ID); if (cv.AllEduQualifications != null && cv.AllEduQualifications.Count > 0) { foreach (ErCVEducation item in cv.AllEduQualifications) { item.EducationLevels = new EducationLevelService().GetByID(tc, item.DegreeTitleID); item.Disciplines = new DisciplineService().GetByID(tc, item.DisciplineID); } } cv.CVReferences = GetAllReferences(tc, cv.ID); cv.CVTrainings = GetAllTrainings(tc, cv.ID); var erCVProfilePhoto = GetAllAttachments(tc, cv.ID,EnumFileType.ErCVProfilePhoto); if(erCVProfilePhoto != null && erCVProfilePhoto.Count > 0) cv.ErCVProfilePhoto = erCVProfilePhoto[0]; cv.IRFileAttacments = GetAllAttachments(tc, cv.ID, EnumFileType.ErCV); } tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return cv; } private List GetAllAttachments(TransactionContext tc, int cvID, EnumFileType type) { List allExps = null; try { DataReader oreader = new DataReader(FileAttachmentDA.GetByReferenceId(tc, cvID, type)); allExps = this.CreateirFileAttachmentObjects(oreader); oreader.Close(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return allExps; } private List GetAllAttachments(TransactionContext tc, int cvID) { List allExps = null; try { DataReader oreader = new DataReader(FileAttachmentDA.GetErCv(tc, cvID)); allExps = this.CreateirFileAttachmentObjects(oreader); oreader.Close(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return allExps; } private List GetAllReferences(TransactionContext tc, int cVID) { List allExps = null; try { DataReader oreader = new DataReader(ErCVReferenceDA.Get(cVID, tc)); allExps = this.CreateReferenceObjects(oreader); oreader.Close(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return allExps; } private List GetAllEducations(TransactionContext tc, int cVID) { List allExps = null; try { DataReader oreader = new DataReader(ErCVDA.GetEducationQualifications(cVID, tc)); allExps = this.CreateEductionalQualificationObjects(oreader); oreader.Close(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return allExps; } private List GetAllTrainings(TransactionContext tc, int cVID) { List allExps = null; try { DataReader oreader = new DataReader(ErCVDA.GetErCVTraining(cVID, tc)); allExps = this.CreateErCVTrainingObjects(oreader); oreader.Close(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return allExps; } public List GetPreviousCVbyRequisitionID(int requisitionID) { List allCVs = null; InternalRecruitment Requisition = null; List usercvs = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(CVDA.GetPreviousCvOfRequisition(tc, requisitionID)); allCVs = this.CreateObjects(oreader); oreader.Close(); foreach (ErCV cv in allCVs) { if (cv != null) { cv.AllExperiences = GetAllExp(tc, cv.ID); cv.AllEduQualifications = GetAllEducations(tc, cv.ID); if (cv.AllEduQualifications != null && cv.AllEduQualifications.Count > 0) { foreach (ErCVEducation item in cv.AllEduQualifications) { item.EducationLevels = new EducationLevelService().GetByID(tc, item.DegreeTitleID); item.Disciplines = new DisciplineService().GetByID(tc, item.DisciplineID); } } cv.CVReferences = GetAllReferences(tc, cv.ID); //cv.IRFileAttacments = GetAllAttachments(tc, cv.ID, EnumFileType.CV); } } if (allCVs != null && allCVs.Count > 0) { Requisition = new InternalRecruitmentService().Get(allCVs[0].PositionID); if (Requisition != null) { DataReader oreader1 = new DataReader(CVDA.GetUserCVSortByRequisitionID(requisitionID, tc)); while (oreader1.Read()) { ErUserCvSort item = new ErUserCvSort(); item.ID = oreader1.GetInt32("UserCvSortId").Value; item.PositionID = oreader1.GetInt32("RequisitionID", 0); item.CandidateID = oreader1.GetInt32("CandidateID", 0); item.SelectStatus = oreader1.GetBoolean("SelectStatus", false); usercvs.Add(item); } oreader1.Close(); } } tc.End(); if (Requisition != null && Requisition.OnBoradStatus == EnumOnBoradStatus.CVCollection) { foreach (ErCV cv in allCVs) { var userCvExit = usercvs?.Where(x => (x.PositionID == cv.PositionID) && (x.CandidateID == cv.CandidateID) && x.SelectStatus == true)?.Any(); if (userCvExit != null && userCvExit == true) { cv.SortStatus = "Selected"; } else { cv.SortStatus = "Rejected"; } } } } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return allCVs; } public bool IsRequisitionComplete(int requisitionID) { List usercvs = new List(); TransactionContext tc = null; bool isRequisitionComplete = true; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(CVDA.GetCVSortByRequisitionID(requisitionID, tc)); while (oreader.Read()) { ErCVSort item = new ErCVSort(); item.ID = oreader.GetInt32("CVSortID").Value; item.EmployeeID = oreader.GetInt32("EmployeeID", 0); item.RequisitionID = oreader.GetInt32("RequisitionID", 0); item.WfStatus = oreader.GetString("WfStatus") != null ? (EnumWFCvSortStatus)oreader.GetInt32("WfStatus").Value : EnumWFCvSortStatus.Not_Yet_Completed; usercvs.Add(item); } oreader.Close(); tc.End(); if (usercvs != null && usercvs.Count > 0) { foreach (var item in usercvs) { if (item.WfStatus == EnumWFCvSortStatus.Not_Yet_Completed) { isRequisitionComplete = false; break; } } } else { isRequisitionComplete = false; } } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return isRequisitionComplete; } private List GetAllExp(TransactionContext tc, int cVID) { List allExps = null; try { DataReader oreader = new DataReader(ErCVDA.GetExperiences(cVID, tc)); allExps = this.CreateExperienceObjects(oreader); oreader.Close(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return allExps; } public List GetCVAttachmentbyID(int cvId) { List oFileAttachments = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(FileAttachmentDA.GetByReferenceId(tc, cvId, EnumFileType.ErCV)); oFileAttachments = this.CreateirFileAttachmentObjects(oreader); oreader.Close(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException("Failed to Get IRNotifications: " + ex.Message, ex); #endregion } return oFileAttachments; } #endregion #region List< CV > GetByQuery(string query) public List GetByQuery(string query) { List allCVs = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(CVDA.GetByQuery(query, tc)); allCVs = this.CreateObjects(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 allCVs; } public DataTable dtGetCVByID(int cvID) { DataSet ds = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ds = CVDA.dtGetCVByID(tc, cvID); tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return ds.Tables[0]; } //public DataTable dtGetRecruitmentbyCVSort(int employeeID) //{ // DataSet ds = new DataSet(); // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(true); // ds = CVDA.dtGetRecruitmentbyCVSort(tc, employeeID); // tc.End(); // } // catch (Exception ex) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(ex); // throw new ServiceException(ex.Message, ex); // #endregion // } // return ds.Tables[0]; //} public List dtGetRecruitmentbyCVSort(int employeeID) { List sortItems = new List(); RecruitmentByCVSort sortItem = null; DataSet ds = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); ds = CVDA.dtGetRecruitmentbyCVSort(tc, employeeID); tc.End(); if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow Dr in ds.Tables[0].Rows) { sortItem = new RecruitmentByCVSort(); sortItem.AssignedDatetime = Convert.ToDateTime(Dr["AssignedDatetime"]).ToString("dd MMM yyyy"); sortItem.PositionID = Convert.ToInt32(Dr["PositionID"].ToString()); sortItem.PositionName = Dr["PositionName"] is DBNull ? null : Dr["PositionName"].ToString(); sortItem.OnBoardStatus = (EnumOnBoradStatus)Convert.ToInt16(Dr["OnBoardStatus"].ToString()); sortItem.OnBoardStatusString = EnumDescription.GetEnumDescription(sortItem.OnBoardStatus); sortItem.TotalCV = Dr["TotalCV"] is DBNull ? 0 : Convert.ToInt32(Dr["TotalCV"].ToString()); sortItem.CompleteStatus = (EnumWFCvSortStatus)Convert.ToInt16(Dr["WFSTATUS"].ToString()); sortItems.Add(sortItem); } } } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return sortItems; } public List dtCVSortDetails(int positionID) { List deatilItems = new List(); CVSortDetails detailItem = null; DataSet ds = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); ds = CVDA.dtCVSortDetails(tc, positionID); tc.End(); if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow Dr in ds.Tables[0].Rows) { detailItem = new CVSortDetails(); detailItem.PositionID = Convert.ToInt32(Dr["PositionID"].ToString()); detailItem.PositionName = Dr["PositionName"] is DBNull ? null : Dr["PositionName"].ToString(); detailItem.CandidateName = Dr["Name"] is DBNull ? null : Dr["Name"].ToString(); detailItem.Mobile = Dr["Mobile"] is DBNull ? null : Dr["Mobile"].ToString(); detailItem.Email = Dr["Email"] is DBNull ? null : Dr["Email"].ToString(); detailItem.CandidateID = Convert.ToInt32(Dr["CandidateID"].ToString()); detailItem.CvID = Convert.ToInt32(Dr["CvID"].ToString()); detailItem.UserCvSortID = Dr["UserCvSortID"] is DBNull ? 0 : Convert.ToInt32(Dr["UserCvSortID"] is DBNull ? 0.ToString() : Dr["UserCvSortID"].ToString()); detailItem.IsCVSelect = Convert.ToBoolean(Dr["SELECTSTATUS"] is DBNull ? false.ToString() : Dr["SELECTSTATUS"].ToString()); detailItem.Remarks = Dr["Remarks"] is DBNull ? null : Dr["Remarks"].ToString(); ; deatilItems.Add(detailItem); } } } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return deatilItems; } public List GetAllAttachments(int refID, EnumFileType type) { List allExps = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(FileAttachmentDA.GetByReferenceId(tc, refID, type)); allExps = this.CreateirFileAttachmentObjects(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 allExps; } public List GetCVs() { List allCVs = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(CVDA.GetCVs(tc)); allCVs = this.CreateObjects(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 allCVs; } public List GetCVByIDs(string cVIDs) { List allCVs = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(CVDA.Get(cVIDs, tc)); allCVs = this.CreateObjects(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 allCVs; } public void DeleteUserCvsort(UserCvSort obCv) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); #region Delete UserCvSort CVDA.DeleteUserCvSort(obCv.ID, tc); #endregion tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } } public void UpdateCompleteStatus(int positionID, int employeeID) { TransactionContext tc = null; int oID = 0; try { tc = TransactionContext.Begin(true); CVDA.UpdateEmployeeWFStatus(positionID, employeeID, tc); tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } } List IErCVService.getAllOnlyCV() { throw new NotImplementedException(); } List IErCVService.GetByCvSearch(string name, string email, string mobile) { throw new NotImplementedException(); } List IErCVService.GetCVs() { throw new NotImplementedException(); } List IErCVService.GetCVByIDs(string cVIDs) { throw new NotImplementedException(); } List IErCVService.dtGetRecruitmentbyCVSort(int employeeID) { throw new NotImplementedException(); } List IErCVService.dtCVSortDetails(int positionID) { throw new NotImplementedException(); } public void DeleteUserCvsort(ErUserCvSort obCv) { throw new NotImplementedException(); } #endregion public List GetErCvByRequisitionId(int requisitionId) { List allCVs = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(ErCVDA.GetPortalCvsByRequisition(tc,requisitionId)); allCVs = this.CreateObjects(oreader); oreader.Close(); foreach (ErCV cv in allCVs) { if (cv != null) { cv.AllExperiences = GetAllExp(tc, cv.ID); cv.AllEduQualifications = GetAllEducations(tc, cv.ID); if (cv.AllEduQualifications != null && cv.AllEduQualifications.Count > 0) { foreach (ErCVEducation item in cv.AllEduQualifications) { item.EducationLevels = new EducationLevelService().GetByID(tc, item.DegreeTitleID); item.Disciplines = new DisciplineService().GetByID(tc, item.DisciplineID); } } cv.CVReferences = GetAllReferences(tc, cv.ID); cv.IRFileAttacments = GetAllAttachments(tc, cv.ID, EnumFileType.ErCVProfilePhoto); } } tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return allCVs; } public List GetErCvByCvids(string cvIds) { List allCVs = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(ErCVDA.GetbyErcvIds(cvIds, tc)); allCVs = this.CreateObjects(oreader); oreader.Close(); foreach (ErCV cv in allCVs) { if (cv != null) { cv.AllExperiences = GetAllExp(tc, cv.ID); cv.AllEduQualifications = GetAllEducations(tc, cv.ID); if (cv.AllEduQualifications != null && cv.AllEduQualifications.Count > 0) { foreach (ErCVEducation item in cv.AllEduQualifications) { item.EducationLevels = new EducationLevelService().GetByID(tc, item.DegreeTitleID); item.Disciplines = new DisciplineService().GetByID(tc, item.DisciplineID); } } cv.CVReferences = GetAllReferences(tc, cv.ID); cv.IRFileAttacments = GetAllAttachments(tc, cv.ID); } } tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return allCVs; } #endregion #endregion } }