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; namespace HRM.DA { public class ErCircularService : ServiceTemplate, IErCircularService { #region ErCircularService Object Mapping private void MapErCricularObject(ErCircular obErCircular, DataReader oReader) { this.SetObjectID(obErCircular, oReader.GetInt32("ERCircularID").Value); obErCircular.RecruitementID = oReader.GetInt32("RecruitementID", true, 0); obErCircular.PublishFrom = oReader.GetDateTime("PublishFromDate").HasValue ? oReader.GetDateTime("PublishFromDate").Value : DateTime.MinValue; obErCircular.PublishTo = oReader.GetDateTime("PublishToDate").HasValue ? oReader.GetDateTime("PublishToDate").Value : DateTime.MinValue; obErCircular.CreatedBy = oReader.GetInt32("CreatedBy", 0); obErCircular.CreatedDate = oReader.GetDateTime("CreationDate").HasValue ? oReader.GetDateTime("CreationDate").Value : DateTime.MinValue; obErCircular.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); obErCircular.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue ? oReader.GetDateTime("ModifiedDate").Value : (DateTime?)null; obErCircular.RecruitmentNo = oReader.GetString("POSITIONNAME", true, null); obErCircular.RecruitmentDate = oReader.GetDateTime("PositionDate",true,DateTime.MinValue); this.SetObjectState(obErCircular, ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { ErCircular obErCircular = new ErCircular(); MapErCricularObject(obErCircular, oReader); return obErCircular as T; } private ErCircular CreateObject(DataReader oReader) { ErCircular obErCircular = new ErCircular(); MapErCricularObject(obErCircular, oReader); return obErCircular; } #endregion #region Service Implementation #region Insert(ErCircular erCricular) public void Save(ErCircular erCricular) { TransactionContext tc = null; int oID = 0; try { tc = TransactionContext.Begin(true); if (erCricular.IsNew) { int id = tc.GenerateID("ER_Circular", "ERCircularID"); oID = (id); base.SetObjectID(erCricular, (id)); ErCircularDA.InsertErCircular(erCricular, tc); RecJobTrackingDA.UpdateactualJobPosting(tc, erCricular.RecruitementID); InternalRecruitmentDA.UpdateRequisitionStatus(tc, erCricular.RecruitementID,EnumOnBoradStatus.CVPosting); } else { oID = erCricular.ID; ErCircularDA.UpdateErCircular(erCricular, tc); } ErCircularDetailDA.DeleteByParentID(oID,tc); ErCircularSurveyDA.DeleteByCircularID(oID, tc); int seqNo=ErCircularDetailDA.GetSequenceNo(tc); if (erCricular.ErCircularDetails != null && erCricular.ErCircularDetails.Count > 0) { foreach (var item in erCricular.ErCircularDetails) { int itemid = tc.GenerateID("ER_CircularDetail", "ERCircularDetailID"); item.ERCircularID = oID; item.SequenceNo = seqNo; base.SetObjectID(item, (itemid)); ErCircularDetailDA.InsertErCircularDetail(item,tc); } } if (erCricular.ErCircularSurveyList != null && erCricular.ErCircularSurveyList.Count > 0) { foreach (var item in erCricular.ErCircularSurveyList) { item.ERCircularID = oID; ErCircularSurveyDA.InsertErCircularSurvey(item, 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 GetReferredBy(int cVID) public List Get() { List allRefs = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(ErCircularDA.Get(tc)); allRefs = 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 allRefs; } #endregion #region Get(int cVID) public ErCircular Get(int erCircularID) { ErCircular cv = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(ErCircularDA.Get(tc, erCircularID)); if (oreader.Read()) { cv = this.CreateObject(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 cv; } public ErCircular GetByRequisition(int requisitionID) { ErCircular circular = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(ErCircularDA.GetByRecruitmentID(tc, requisitionID)); if (oreader.Read()) { circular = this.CreateObject(oreader); } oreader.Close(); tc.End(); if (circular != null) { circular.ErCircularDetails = new ErCircularDetailService().GetByParentId(circular.ID); circular.ErCircularSurveyList = new ErCircularSurveyService().GetByCircularID(circular.ID); } } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return circular; } public List GetAll() { List allRefs = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(ErCircularDA.GetAll(tc)); allRefs = 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 allRefs; } #endregion public void Delete(ErCircular oErCircular) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); #region Delete ErCircular ErCircularDA.Delete(oErCircular.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 } } #endregion } }