using System; using System.Data; using System.Linq; using Ease.Core.Model; using Ease.Core.DataAccess; using HRM.BO; using System.Collections.Generic; using Ease.Core.Utility; namespace HRM.DA { #region Organogram Service public class OrganogramService : ServiceTemplate, IOrganogramService { #region Private functions and declaration public OrganogramService() { } private void MapObject(OrganogramBasic oOrganogram, DataReader oReader) { base.SetObjectID(oOrganogram, oReader.GetInt32("OrganogramID").Value); oOrganogram.PositionName = oReader.GetString("PositionName"); oOrganogram.ParentID = oReader.GetInt32("ParentID"); oOrganogram.Tier = oReader.GetInt32("Tier").Value; oOrganogram.UniqueId = oReader.GetInt32("UniqueId").Value; //oOrganogram.PositionTypeID = oReader.GetID("PositionTypeID"); oOrganogram.PositionNo = oReader.GetString("PositionNo"); oOrganogram.CompanyID = oReader.GetInt32("CompanyID", 0); oOrganogram.DepartmentID = oReader.GetInt32("DepartmentID").Value; oOrganogram.FunctionID = oReader.GetInt32("FunctionID", 0); oOrganogram.GradeID = oReader.GetInt32("GradeID"); oOrganogram.DesignationID = oReader.GetInt32("DesignationID").Value; oOrganogram.LocationID = oReader.GetInt32("LocationID").Value; //oOrganogram.ReportingNodeID = oReader.GetID("RepotingNodeID"); oOrganogram.Tier = oReader.GetInt32("Tier").Value; oOrganogram.Sequence = oReader.GetInt32("SequenceNO").Value; oOrganogram.Status = (EnumStatus)oReader.GetInt32("Status").Value; oOrganogram.JDNo = oReader.GetString("JDNo"); oOrganogram.RevisionNo = oReader.GetString("RevisionNo") == null ? "" : oReader.GetString("RevisionNo"); oOrganogram.RevisionDate = oReader.GetDateTime("RevisionDate").GetValueOrDefault(); oOrganogram.CreatedBy = oReader.GetInt32("CreatedBy").Value; oOrganogram.CreatedDate = oReader.GetDateTime("CreationDate").Value; oOrganogram.ModifiedBy = oReader.GetInt32("ModifiedBy"); oOrganogram.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oOrganogram, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { OrganogramBasic oOrganogram = new OrganogramBasic(); MapObject(oOrganogram, oReader); return oOrganogram as T; } private void MapOrganAuthorityObject(OrganogramAuthority organAuthority, DataReader oReader) { base.SetObjectID(organAuthority, oReader.GetInt32("OrganAuthorityID").Value); organAuthority.NodeID = oReader.GetInt32("NodeID", 0); organAuthority.AuthorityType = (EnumAuthorityType)oReader.GetInt32("AuthorityType").Value; organAuthority.ChildNodeID = oReader.GetInt32("ChildNodeID", 0); organAuthority.EmployeeID = oReader.GetInt32("EmployeeID", 0); //organAuthority.ModifiedBy = oReader.GetID("ModifiedBy"); // organAuthority.ModifiedDate = oReader.GetDateTime("ModifiedDate").Value; this.SetObjectState(organAuthority, Ease.Core.ObjectState.Saved); } protected List CreateOrganAuthorityObject(DataReader oReader) { List organAuthorities = new List(); while (oReader.Read()) { OrganogramAuthority organAuthority = new OrganogramAuthority(); MapOrganAuthorityObject(organAuthority, oReader); organAuthorities.Add(organAuthority); } return organAuthorities; } private void MapOrganDelegationObject(OrganogramDelegation organDelegation, DataReader oReader) { base.SetObjectID(organDelegation, oReader.GetInt32("OrganDelegationID").Value); organDelegation.NodeID = oReader.GetInt32("NodeID", 0); organDelegation.EmployeeID = oReader.GetInt32("EmployeeID", 0); organDelegation.FromDate = oReader.GetDateTime("FromDate").Value; organDelegation.ToDate = oReader.GetDateTime("ToDate").Value; organDelegation.DelegationType = oReader.GetString("DelegationType"); organDelegation.IsActive = oReader.GetBoolean("IsActive").Value; organDelegation.CreatedBy = oReader.GetInt32("CreatedBy", 0); organDelegation.CreatedDate = oReader.GetDateTime("CreationDate").Value; organDelegation.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); organDelegation.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(organDelegation, Ease.Core.ObjectState.Saved); } public List GetOrganogramAutoriyEmployee(List oEmps, List oOrgEmployees, List oOrgBasics, List oOrgAuthorities, EnumAuthorityType authType, Employee oEmployee) { List oInternalEmployees = new List(); OrganogramEmployee oORgEmployee = oOrgEmployees.FirstOrDefault(x => x.EmployeeID == oEmployee.ID); if (oORgEmployee != null) { OrganogramBasic orgBasic = oOrgBasics.FirstOrDefault(x => x.ID == oORgEmployee.NodeID); if (orgBasic != null) { List oOrgAuthority = oOrgAuthorities.Where(x => x.NodeID == orgBasic.ID && x.AuthorityType == authType).ToList(); //StringBuilder sb = new StringBuilder(); foreach (OrganogramAuthority item in oOrgAuthority) { OrganogramBasic orgBasicTemp = oOrgBasics.FirstOrDefault(x => x.ID == item.ChildNodeID); if (orgBasicTemp != null) { Employee oEmpTemp = oEmps.FirstOrDefault(x => x.EmployeeNo.Trim().ToUpper() == orgBasicTemp.PositionNo.ToString().Trim()); if (oEmpTemp != null) { oInternalEmployees.Add(oEmpTemp); //sb.AppendFormat("{0},", oEmpTemp.Name); } } } } } return oInternalEmployees; } protected List CreateOrganDelegationObject(DataReader oReader) { List organDelegations = new List(); while (oReader.Read()) { OrganogramDelegation organDelegation = new OrganogramDelegation(); MapOrganDelegationObject(organDelegation, oReader); organDelegations.Add(organDelegation); } return organDelegations; } private void MapOrganJobDescObject(OrganogramJobDesc organJobDesc, DataReader oReader) { base.SetObjectID(organJobDesc, oReader.GetInt32("OrganJobDescID").Value); organJobDesc.NodeID = oReader.GetInt32("NodeID", 0); organJobDesc.Purpose = oReader.GetString("Purpose"); organJobDesc.JobSummery = oReader.GetString("JobSummery"); organJobDesc.Experience = oReader.GetString("Experience"); organJobDesc.Education = oReader.GetString("Education"); organJobDesc.CreatedBy = oReader.GetInt32("CreatedBy", 0); organJobDesc.CreatedDate = oReader.GetDateTime("CreationDate").Value; organJobDesc.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); //organDelegation.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(organJobDesc, Ease.Core.ObjectState.Saved); } protected List CreateOrganJobDescObject(DataReader oReader) { List organJobDescs = new List(); while (oReader.Read()) { OrganogramJobDesc organJobDesc = new OrganogramJobDesc(); MapOrganJobDescObject(organJobDesc, oReader); organJobDescs.Add(organJobDesc); } return organJobDescs; } private void MapOrganResponsibilityObject(OrganogramResponsibility organResp, DataReader oReader) { base.SetObjectID(organResp, oReader.GetInt32("OrganResponsibilityID").Value); organResp.NodeID = oReader.GetInt32("NodeID", 0); organResp.Responsibility = oReader.GetString("Responsibility"); organResp.IsPrimary = oReader.GetBoolean("IsPrimary").Value; //organResp.CreatedBy = oReader.GetID("CreatedBy"); //organResp.CreatedDate = oReader.GetDateTime("CreationDate").Value; //organResp.ModifiedBy = oReader.GetID("ModifiedBy"); //organResp.ModifiedDate = oReader.GetDateTime("ModifiedDate").Value; this.SetObjectState(organResp, Ease.Core.ObjectState.Saved); } protected List CreateOrganResponsibilityObject(DataReader oReader) { List organResponsibilities = new List(); while (oReader.Read()) { OrganogramResponsibility organResponsibility = new OrganogramResponsibility(); MapOrganResponsibilityObject(organResponsibility, oReader); organResponsibilities.Add(organResponsibility); } return organResponsibilities; } private void MapOrganSkilLevelObject(OrganogramSkillLevel organSlilLevel, DataReader oReader) { base.SetObjectID(organSlilLevel, oReader.GetInt32("OrganSkillLevelID").Value); organSlilLevel.NodeID = oReader.GetInt32("NodeID", 0); //organSlilLevel.NodeResponsibilityID = oReader.GetID("NodeResponsibilityID"); organSlilLevel.LevelID = oReader.GetInt32("LevelID", 0); organSlilLevel.SkillID = oReader.GetInt32("SkillID", 0); //organSlilLevel.CreatedBy = oReader.GetID("CreatedBy"); //organSlilLevel.CreatedDate = oReader.GetDateTime("CreationDate").Value; //organSlilLevel.ModifiedBy = oReader.GetID("ModifiedBy"); //organSlilLevel.ModifiedDate = oReader.GetDateTime("ModifiedDate").Value; this.SetObjectState(organSlilLevel, Ease.Core.ObjectState.Saved); } protected List CreateOrganSkilLevelObject(DataReader oReader) { List organSkilLevels = new List(); while (oReader.Read()) { OrganogramSkillLevel organSkilLevel = new OrganogramSkillLevel(); MapOrganSkilLevelObject(organSkilLevel, oReader); organSkilLevels.Add(organSkilLevel); } return organSkilLevels; } private void MapOrganPositionObject(OrganogramPosition OrganPosition, DataReader oReader) { base.SetObjectID(OrganPosition, oReader.GetInt32("OrganPositionID").Value); OrganPosition.NodeID = oReader.GetInt32("NodeID").Value; OrganPosition.PositionTypeID = oReader.GetInt32("PositionTypeID").Value; // OrganPosition.CreatedBy = oReader.GetInt32("CreatedBy").Value; //OrganPosition.CreatedDate = oReader.GetDateTime("CreationDate").Value; // OrganPosition.ModifiedBy = oReader.GetID("ModifiedBy"); // OrganPosition.ModifiedDate = oReader.GetDateTime("ModifiedDate").Value; this.SetObjectState(OrganPosition, Ease.Core.ObjectState.Saved); } protected List CreateOrganPositionObject(DataReader oReader) { List organPositions = new List(); while (oReader.Read()) { OrganogramPosition organPosition = new OrganogramPosition(); MapOrganPositionObject(organPosition, oReader); organPositions.Add(organPosition); } return organPositions; } #endregion #region Service implementation #region Insert public int Save(OrganogramBasic oOrganogram) { TransactionContext tc = null; int id=0; try { tc = TransactionContext.Begin(true); id = this.Save(tc, oOrganogram); tc.End(); return oOrganogram.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); //string smessage = "Faliled to save Organogram (table:" + tableName + ") for the Position:(" // + oOrganogram.PositionNo + ") " + oOrganogram.PositionName + ". Error :"; throw new ServiceException(e.Message, e); #endregion } return id; } public int Save(TransactionContext tc ,OrganogramBasic oOrganogram) { try { int id = 0; if (oOrganogram.IsNew) { id = tc.GenerateID("Organogram", "OrganogramID"); base.SetObjectID(oOrganogram, (id)); OrganogramDA.Insert(tc, oOrganogram); } else { OrganogramDA.Update(tc, oOrganogram); OrganogramDA.DeleteOrganAuthority(tc, oOrganogram.ID); OrganogramDA.DeleteOrganDelegation(tc, oOrganogram.ID); OrganogramDA.DeleteOranJobDesc(tc, oOrganogram.ID); OrganogramDA.DeleteOrganResponsibility(tc, oOrganogram.ID); OrganogramDA.DeleteOrganSkilLevel(tc, oOrganogram.ID); OrganogramDA.DeleteOrganPosition(tc, oOrganogram.ID); } //tableName = "OrganAuthority"; foreach (OrganogramAuthority organAuthor in oOrganogram.OrganAuthority) { id = tc.GenerateID("OrganAuthority", "OrganAuthorityID"); organAuthor.NodeID = oOrganogram.ID; base.SetObjectID(organAuthor, (id)); OrganogramDA.Insert(tc, organAuthor); } //tableName = "OrganDelegation"; foreach (OrganogramDelegation organDele in oOrganogram.OrganDelegation) { id = tc.GenerateID("OrganDelegation", "OrganDelegationID"); organDele.NodeID = oOrganogram.ID; base.SetObjectID(organDele, (id)); OrganogramDA.Insert(tc, organDele); } //tableName = "OrganJobDescription"; foreach (OrganogramJobDesc organJob in oOrganogram.OrganJobDesc) { id = tc.GenerateID("OrganJobDescription", "OrganJobDescID"); organJob.NodeID = oOrganogram.ID; organJob.CreatedBy = oOrganogram.CreatedBy; organJob.CreatedDate = oOrganogram.CreatedDate; base.SetObjectID(organJob, (id)); OrganogramDA.Insert(tc, organJob); } //tableName = "OrganResponsibility"; foreach (OrganogramResponsibility organRes in oOrganogram.OrganResponsibility) { id = tc.GenerateID("OrganResponsibility", "OrganResponsibilityID"); organRes.NodeID = oOrganogram.ID; base.SetObjectID(organRes, (id)); OrganogramDA.Insert(tc, organRes); } //tableName = "OrganSkillLevel"; foreach (OrganogramSkillLevel organSkillLvl in oOrganogram.OrganSkillLevel) { id = tc.GenerateID("OrganSkillLevel", "OrganSkillLevelID"); organSkillLvl.NodeID = oOrganogram.ID; base.SetObjectID(organSkillLvl, (id)); OrganogramDA.Insert(tc, organSkillLvl); } //tableName = "OrganPosition"; if (oOrganogram.OrganPositions != null) { foreach (OrganogramPosition organPosn in oOrganogram.OrganPositions) { id = tc.GenerateID("OrganPosition", "OrganPositionID"); organPosn.NodeID = oOrganogram.ID; base.SetObjectID(organPosn, (id)); OrganogramDA.Insert(tc, organPosn); } } return oOrganogram.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); //string smessage = "Faliled to save Organogram (table:" + tableName + ") for the Position:(" // + oOrganogram.PositionNo + ") " + oOrganogram.PositionName + ". Error :"; throw new ServiceException(e.Message, e); #endregion } } #endregion #region Delete public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); OrganogramDA.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 } } public void DeleteAll() { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); OrganogramDA.DeleteAll(tc); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion #region Get public List GetAllOrganAuthority() { List Organograms = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramDA.GetAllOrganAuthority(tc)); Organograms = this.CreateOrganAuthorityObject(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 Organograms; } public OrganogramBasic GetbyEmployeeid(int employeeid) { List Organograms = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramDA.GetbyEmployeeID(tc, employeeid)); Organograms = 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 } if (Organograms != null && Organograms.Count > 0) return Organograms[0]; else return null; } public int GetMaxTier(TransactionContext tc) { int maxLevel = 0; try { #region Retrieving data maxLevel = OrganogramDA.GetMaxTier(tc); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return maxLevel; } public OrganogramBasic Get(int id) { OrganogramBasic oOrganogram = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(OrganogramDA.Get(tc, id)); if (oreader.Read()) { oOrganogram = this.CreateObject(oreader); } oreader.Close(); if (oOrganogram != null) { OrganogramEmployeeService ore = new OrganogramEmployeeService(); oOrganogram.OrganEmployees = ore.Get(tc, oOrganogram.ID); DataReader dr = new DataReader(OrganogramDA.Get4OrganPosition(tc, oOrganogram.ID)); oOrganogram.OrganPositions = this.CreateOrganPositionObject(dr); dr.Close(); //dr = new DataReader(OrganogramDA.Get4OrganAuthority(tc, oOrganogram.ID)); //oOrganogram.OrganAuthority = this.CreateOrganAuthorityObject(dr); //dr.Close(); //dr = new DataReader(OrganogramDA.Get4OrganJobDesc(tc, oOrganogram.ID)); //oOrganogram.OrganJobDesc = this.CreateOrganJobDescObject(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 oOrganogram; } public List Get(EnumStatus status) { List Organograms = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramDA.Get(tc, status)); Organograms = 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 Organograms; } public List GetbyTier(int fromTier, int toTier) { List Organograms = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramDA.GetbyTier(tc, fromTier, toTier)); Organograms = 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 Organograms; } public List GetbyPositionTypeID(int postiontypeid) { List Organograms = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramDA.GetbyPositionType(tc, postiontypeid)); Organograms = 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 Organograms; } public List GetTopParents(EnumStatus status) { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramDA.GetTopParents(tc, status)); items = 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 items; } public List GetByParentID(int parentID, EnumStatus status) { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramDA.GetByParentID(tc, parentID, status)); items = 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 items; } public List Get4OrganAuthority(int nodeID) { List Organograms = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramDA.Get4OrganAuthority(tc, nodeID)); Organograms = this.CreateOrganAuthorityObject(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 Organograms; } public List Get4OrganDelegation(int nodeID) { List Organograms = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramDA.Get4OrganDelegation(tc, nodeID)); Organograms = this.CreateOrganDelegationObject(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 Organograms; } public List Get4OrganJobDesc(int nodeID) { List Organograms = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramDA.Get4OrganJobDesc(tc, nodeID)); Organograms = this.CreateOrganJobDescObject(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 Organograms; } public List Get4OrganResponsibility(int nodeId) { List Organograms = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramDA.Get4OrganResponsibility(tc, nodeId)); Organograms = this.CreateOrganResponsibilityObject(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 Organograms; } public List Get4OrganSkilLevel(int nodeID) { List Organograms = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramDA.Get4OrganSkilLevel(tc, nodeID)); Organograms = this.CreateOrganSkilLevelObject(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 Organograms; } public List Get4OrganPosition(int nodeID) { List Organograms = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramDA.Get4OrganPosition(tc, nodeID)); Organograms = this.CreateOrganPositionObject(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 Organograms; } public List GetAllOrganPosition() { List Organograms = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramDA.GetAllOrganPosition(tc)); Organograms = this.CreateOrganPositionObject(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 Organograms; } public List GetOrganAuthorityByEmp(int EmpID) { List Organograms = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramDA.GetOrganAuthorityByEmp(tc, EmpID)); Organograms = this.CreateOrganAuthorityObject(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 Organograms; } public DataTable GetManagers(string sEmpIDs) { DataTable dataTableOfEmployee = new DataTable("Employee"); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataSet dataSet = OrganogramDA.GetManagers(tc, sEmpIDs); dataTableOfEmployee = dataSet.Tables[0]; dataSet.Dispose(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return dataTableOfEmployee; } public void UpdateParentAndTier(List oNodes) { try { TransactionContext tc = null; try { #region Update data tc = TransactionContext.Begin(true); foreach (OrganogramBasic oNode in oNodes) { OrganogramDA.UpdateParentAndTier(tc, oNode); if(oNode.ParentID !=null) HREmployeeDA.updateLineManagerOnlyByOrganogram(tc, oNode); } tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } } catch (Exception e) { throw new ServiceException(e.Message, e); } } public int GetMinNodeIdByDept(int deptID) { OrganogramBasic oOrganogram = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(OrganogramDA.GetMinNodeIdByDept(tc, deptID)); if (oreader.Read()) { oOrganogram = 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 } if (oOrganogram == null) return 0; else return oOrganogram.ID; } public void CreateOrgFromEmployee(int userid) { List emps = new EmployeeService().GetAllEmps(); List desgs = new DesignationService().GetAll(); List parents = emps.FindAll(x => x.LineManagerID == null); this.DeleteAll(); if (parents!=null) { foreach(Employee emp in parents ) { if (emp.Status == EnumEmployeeStatus.Live) this.CreateOrgFromEmp(emps, userid, emp.ID, null,1, desgs); } } } public void CreateOrgFromEmp(List emps,int userid, int empID, int? nodeid,int tier, List designations ) { OrganogramBasic obasic = new OrganogramBasic(); Employee oemp = emps.FirstOrDefault(x => x.ID == empID); var deg = designations.FirstOrDefault(x => x.ID == oemp.DesignationID); if (deg != null) obasic.PositionName = deg.Name; if(oemp.DesignationID!=null) obasic.DesignationID =(int) oemp.DesignationID; if (oemp.LocationID != null) obasic.LocationID =(int) oemp.LocationID; if (oemp.GradeID != null) obasic.GradeID = oemp.GradeID; if (oemp.DepartmentID != null) obasic.DepartmentID =(int) oemp.DepartmentID; if (nodeid != null) obasic.ParentID =(int) nodeid; OrganogramEmployee oge = new OrganogramEmployee(); oge.EmployeeID = empID; oge.CreatedBy = userid; oge.CreatedDate = DateTime.Today; obasic.OrganEmployees = new List(); obasic.OrganEmployees.Add(oge); obasic.CreatedBy = userid; obasic.CreatedDate = DateTime.Today; obasic.Tier = tier; this.Save(obasic); oge.AssignDate = DateTime.Today; oge.NodeID = obasic.ID; new OrganogramEmployeeService().Save(oge); List childs = emps.FindAll(x => x.LineManagerID == empID); if(childs!= null) { foreach(Employee item in childs) { if(item.Status == EnumEmployeeStatus.Live) CreateOrgFromEmp(emps, userid, item.ID, obasic.ID, tier +1, designations); } } } public DataSet GetOrganogramNodes(int nNodeID) { DataSet ds = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); ds = OrganogramDA.GetOrganogramNodes(tc, nNodeID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return ds; } public DataSet GetLMOrganogramNodes(int nNodeID) { DataSet ds = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); ds = OrganogramDA.GetLMOrganogramNodes(tc, nNodeID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return ds; } public int MaxTier() { int tier = 0; TransactionContext tc = null; try { tc = TransactionContext.Begin(); tier = OrganogramDA.MaxTier(tc); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return tier; } #endregion #endregion } #endregion }