using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using HRM.BO; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HRM.DA { public class ExitInterviewService : ServiceTemplate, IExitInterviewService { public ExitInterviewService() { } private void MapObject(ExitInterview oExitInterview, DataReader oReader) { base.SetObjectID(oExitInterview, oReader.GetInt32("ExitInterviewID").Value); oExitInterview.EmployeeID = oReader.GetString("EmployeeID") == null ? 0 : oReader.GetInt32("EmployeeID").Value; oExitInterview.Name = oReader.GetString("Name"); oExitInterview.JobTitle = oReader.GetString("JobTitle"); oExitInterview.DepartmentName = oReader.GetString("DepartmentName"); oExitInterview.ManagerName = oReader.GetString("ManagerName"); oExitInterview.SourceofHire = oReader.GetString("SourceofHire"); oExitInterview.HireDate = oReader.GetDateTime("HireDate"); oExitInterview.TermDate = oReader.GetDateTime("TermDate"); oExitInterview.ExitInteviewDate = oReader.GetDateTime("ExitInteviewDate").Value; oExitInterview.CultureandClimate = oReader.GetString("CultureandClimate"); oExitInterview.CareerDevelopment = oReader.GetString("CareerDevelopment"); oExitInterview.Settingobjectives = oReader.GetString("Settingobjectives"); oExitInterview.Providingfeedbackonperformance = oReader.GetString("Providingfeedbackonperformance"); oExitInterview.Facilitatingteamwork = oReader.GetString("Facilitatingteamwork"); oExitInterview.Communicatinginformationaffects = oReader.GetString("Communicatinginformationaffects"); oExitInterview.Relationshipwithemployees = oReader.GetString("Relationshipwithemployees"); oExitInterview.Other = oReader.GetString("Other"); oExitInterview.CreatedBy = oReader.GetString("CreatedBy") == null ? 0 : oReader.GetInt32("CreatedBy").Value; oExitInterview.CreatedDate = oReader.GetDateTime("CreationDate").Value; oExitInterview.ModifiedBy = oReader.GetString("ModifiedBy") == null ? null : oReader.GetInt32("ModifiedBy").Value; oExitInterview.ModifiedDate = oReader.GetDateTime("ModifiedDate"); oExitInterview.AdditionalComments = oReader.GetString("AdditionalComments"); oExitInterview.ReasonID = (EnumReasonForLeaveing)oReader.GetInt32("ReasonID").Value; this.SetObjectState(oExitInterview, Ease.Core.ObjectState.Saved); } //private void MapReasonForLeavingObject(ReasonsForLeaving oReasonForLeaving, DataReader oReader) //{ // base.SetObjectID(oReasonForLeaving, oReader.GetInt32("ReasonsForLeavingID").Value); // oReasonForLeaving.ExitInterviewID = oReader.GetInt32("ExitInterviewID", 0); // oReasonForLeaving.ReasonID = (EnumReasonForLeaveing)oReader.GetInt32("ReasonID", 0); // this.SetObjectState(oReasonForLeaving, Ease.Core.ObjectState.Saved); //} protected override T CreateObject(DataReader oReader) { ExitInterview oExitInterview = new ExitInterview(); MapObject(oExitInterview, oReader); return oExitInterview as T; } protected ExitInterview CreateObject(DataReader oReader) { ExitInterview oExitInterview = new ExitInterview(); MapObject(oExitInterview, oReader); return oExitInterview; } //protected List CreateReasonForLeavingObjects(DataReader oReader) //{ // List oReasonsForLeavings = new List(); // while (oReader.Read()) // { // ReasonsForLeaving oItem = new ReasonsForLeaving(); // MapReasonForLeavingObject(oItem, oReader); // oReasonsForLeavings.Add(oItem); // } // return oReasonsForLeavings; //} //protected ReasonsForLeaving CreateReasonForLeavingObject(DataReader oReader) //{ // ReasonsForLeaving oReasonsForLeaving = new ReasonsForLeaving(); // MapReasonForLeavingObject(oReasonsForLeaving, oReader); // return oReasonsForLeaving; //} #region Service implementation public ExitInterview Get(int id) { ExitInterview oExitInterview = new ExitInterview(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ExitInterviewDA.Get(tc, id)); if (oreader.Read()) { oExitInterview = 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 oExitInterview; } public ExitInterview GetByEmployeeID(int id) { ExitInterview oExitInterview = new ExitInterview(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ExitInterviewDA.GetByEmployeeID(tc, id)); if (oreader.Read()) { oExitInterview = 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 oExitInterview; } public List Get() { List ExitInterviews = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ExitInterviewDA.Get(tc)); ExitInterviews = 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 ExitInterviews; } //public List GetReasonsForLeaving(int nExitInterviewID) //{ // #region Cache Header // List oReasonsForLeaving = null; // if (oReasonsForLeaving != null) // return oReasonsForLeaving; // #endregion // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(); // DataReader dr = new DataReader(ExitInterviewDA.GetReasonsForLeaving(tc, nExitInterviewID)); // oReasonsForLeaving = this.CreateReasonForLeavingObjects(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 oReasonsForLeaving; //} public List Get(DateTime dtFrom, DateTime dtTo, int nReasonID) { List oExitInterview = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ExitInterviewDA.Get(tc, dtFrom, dtTo, nReasonID)); oExitInterview = 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 oExitInterview; } public int Save(ExitInterview oExitInterview) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oExitInterview.IsNew) { int id = tc.GenerateID("ExitInterview", "ExitInterviewID"); base.SetObjectID(oExitInterview, id); ExitInterviewDA.Insert(tc, oExitInterview); } else { ExitInterviewDA.Update(tc, oExitInterview); } //ExitInterviewDA.DeleteReasonsForLeaving(tc, oExitInterview.ID); //foreach (ReasonsForLeaving oObj in oExitInterview.ReasonsForLeavingCol) //{ // int id = tc.GenerateID("ReasonsForLeaving", "ReasonsForLeavingID"); // base.SetObjectID(oObj, id); // oObj.ExitInterviewID = oExitInterview.ID; // ExitInterviewDA.Insert(tc, oObj); //} tc.End(); return oExitInterview.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ExitInterviewDA.Delete(tc, id); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion } }