public static RoleDetails Find_RoleDetails(tb_Role next_role, tb_Request_Hdr data, tb_WF_Employee employee) { RoleDetails role = new RoleDetails(); role.role_id = next_role.Role_ID; role.role_name = next_role.Role_Desc; if (next_role.Organization_Flag == false) { if (next_role.Assigned_ID != null) { #region Normal role.assigned_person_id = next_role.Assigned_ID; #endregion Normal } else { if (next_role.GroupRole == true) { #region Having Multiple var universal = _Entities.tb_UniversalLookupTable.Where(x => x.Table_Name == next_role.Role_ID && x.IsActive == true).FirstOrDefault(); if (universal != null) { role.assigned_person_id = universal.Table_Name; } #endregion Having Multiple } else { #region Having Single var universal = _Entities.tb_UniversalLookupTable.Where(x => x.Table_Name == next_role.Role_ID && x.IsActive == true && (x.Code == null || x.Code == data.tb_WFType.WF_ID)).FirstOrDefault(); if (universal != null) { role.assigned_person_id = universal.Description; } #endregion Having Single } } } else { #region if (next_role.org_type == null || next_role.org_type == string.Empty) { role.assigned_person_id = employee.Line_Manager; } else if (next_role.org_type.Trim() == "DT")// Check the department table { #region Department var department = _Entities.tb_Department.Where(x => x.IsActive == true && x.Department_Id == employee.Department_Id).FirstOrDefault(); if (department != null) { if (next_role.role_type == "MN" && department.Dept_Manager != null) { role.assigned_person_id = department.Dept_Manager; } else if (next_role.role_type == "CR" && department.Dept_Controller != null) { role.assigned_person_id = department.Dept_Controller; } else if (next_role.role_type == "OA" && department.Dep_Office_Admin != null) { role.assigned_person_id = department.Dep_Office_Admin; } } #endregion Department } else if (next_role.org_type.Trim() == "BL")// Check the business line table { #region Business Line var business = _Entities.tb_BusinessLine.Where(x => x.IsActive == true && x.BL_Id == employee.tb_Department.tb_ProductGroup.BusinessLine_Id).FirstOrDefault(); if (business != null) { if (next_role.role_type == "MN" && business.BL_Manager != null) { role.assigned_person_id = business.BL_Manager; } else if (next_role.role_type == "CR" && business.BL_Controller != null) { role.assigned_person_id = business.BL_Controller; } else if (next_role.role_type == "OA" && business.BL_Office_Admin != null) { role.assigned_person_id = business.BL_Office_Admin; } } #endregion Business Line } else if (next_role.org_type.Trim() == "B")// Check the business { #region Business var business = _Entities.tb_Business.Where(x => x.IsActive == true && x.Bus_Id == employee.tb_Department.tb_ProductGroup.tb_BusinessLine.Business_Id).FirstOrDefault(); if (business != null) { if (next_role.role_type == "MN" && business.Bus_Manager != null) { role.assigned_person_id = business.Bus_Manager; } else if (next_role.role_type == "CR" && business.Bus_Controller != null) { role.assigned_person_id = business.Bus_Controller; } else if (next_role.role_type == "OA" && business.Bus_Office_Admin != null) { role.assigned_person_id = business.Bus_Office_Admin; } } #endregion Business } else if (next_role.org_type == "PG")// Check the Product group table { #region Product Group var product = _Entities.tb_ProductGroup.Where(x => x.IsActive == true && x.PG_Id == employee.tb_Department.PG_Id).FirstOrDefault(); if (product != null) { if (next_role.role_type == "MN" && product.PG_Manager != null) { role.assigned_person_id = product.PG_Manager; } else if (next_role.role_type == "CR" && product.PG_Controller != null) { role.assigned_person_id = product.PG_Controller; } else if (next_role.role_type == "OA" && product.PG_Office_Admin != null) { role.assigned_person_id = product.PG_Office_Admin; } } #endregion Product Group } #endregion } var next_emp = _Entities.tb_WF_Employee.Where(x => x.LocalEmplyee_ID == role.assigned_person_id && x.IsActive == true).FirstOrDefault(); #region if (next_emp != null) { role.assigned_person_id = next_emp.LocalEmplyee_ID; if (next_emp.DelegationFlag == true) { role.deligated_personId = next_emp.Delegate_Emp_Code == null ? next_emp.LocalEmplyee_ID : next_emp.Delegate_Emp_Code; } else { role.deligated_personId = next_emp.LocalEmplyee_ID; } if (role.deligated_personId == data.Employee_ID) { //var bus_line = _entity.tb_BusinessLine.Where(x => x.BL_Id == employee.BusinessLine_Id && x.Country_Id == country.Id && x.IsActive == true).FirstOrDefault(); //var line_manager = _entity.tb_WF_Employee.Where(x => x.LocalEmplyee_ID == bus_line.BL_Manager && x.IsActive == true).FirstOrDefault(); var line_manager = _Entities.tb_WF_Employee.Where(x => x.LocalEmplyee_ID == employee.Line_Manager && x.IsActive == true).FirstOrDefault(); if (line_manager != null) { if (line_manager.DelegationFlag == true) { role.assigned_person_id = line_manager.Delegate_Emp_Code == null ? line_manager.LocalEmplyee_ID : line_manager.Delegate_Emp_Code; } else { role.assigned_person_id = line_manager.LocalEmplyee_ID; } } } } else { role.deligated_personId = role.assigned_person_id; } #endregion return(role); }
public static List <SelectListItem> EscalatedToList(string request_id, string my_id, int escalation_no) { var requests = _Entities.tb_Request_Hdr.Where(x => x.Request_ID == request_id && x.IsActive == true).FirstOrDefault(); var currentescalation = requests.tb_WF_Template; //Fixed Escalation issue – shows same person(Preema) var profile_type = _Entities.tb_WF_Employee.Where(x => x.LocalEmplyee_ID == requests.Employee_ID && x.IsActive == true).FirstOrDefault(); var initiator = _Entities.tb_WF_Employee.Where(x => x.LocalEmplyee_ID == requests.Employee_ID && x.IsActive == true).FirstOrDefault(); var template_type = _Entities.tb_WF_Template.Where(x => x.WF_ID == requests.WF_ID && x.IsActive == true && x.Profile_ID != null).ToList(); var template_data = _Entities.tb_WF_Template.Where(x => x.WF_Template_ID == requests.tb_WF_Template.WF_Template_ID && x.WF_ID == requests.WF_ID && x.Sequence_NO == escalation_no && x.Status_ID == "ESC" && x.IsActive == true).OrderBy(x => x.Sequence_NO).ToList(); if (template_type.Count > 0) { template_data = _Entities.tb_WF_Template.Where(x => x.WF_Template_ID == requests.tb_WF_Template.WF_Template_ID && x.WF_ID == requests.WF_ID && x.Sequence_NO == escalation_no && x.Status_ID == "ESC" && x.IsActive == true && x.Profile_ID == profile_type.Profile_ID).OrderBy(x => x.Sequence_NO).ToList(); } List <EscalationPersonsList> list = new List <EscalationPersonsList>(); foreach (var item in template_data) { EscalationPersonsList one = new EscalationPersonsList(); //var roleTable = _Entities.tb_Role.Where(x => x.Id == item.Role_ID && x.IsActive == true ).FirstOrDefault(); RoleDetails roleTable = Find_RoleDetails(item.tb_Role, requests, initiator); if (roleTable != null) { var emp = _Entities.tb_WF_Employee.Where(x => x.LocalEmplyee_ID == roleTable.assigned_person_id && x.IsActive == true).FirstOrDefault(); one.roleId_name = roleTable.role_name + " - " + emp.Emp_Name; one.emp_localId = roleTable.assigned_person_id + "~" + item.Id; list.Add(one); //if (emp != null) //{ // if (emp.LocalEmplyee_ID != my_id) // { // if (emp.Delegate_Emp_Code == emp.LocalEmplyee_ID) // { // one.roleId_name = roleTable.role_name + " - " + emp.Emp_Name; // one.emp_localId = emp.LocalEmplyee_ID + '~' + item.Id; // } // else if (emp.DelegationFlag == false) // { // one.roleId_name = roleTable.role_name + " - " + emp.Emp_Name; // one.emp_localId = emp.LocalEmplyee_ID + '~' + item.Id; // } // else // { // var newEmp = _Entities.tb_WF_Employee.Where(x => x.LocalEmplyee_ID == roleTable.assigned_person_id && x.IsActive == true).FirstOrDefault(); // one.roleId_name = roleTable.role_name + " - " + newEmp.Emp_Name; // one.emp_localId = newEmp.LocalEmplyee_ID + '~' + item.Id; // } // list.Add(one); // } //} } } return(list.Select(x => new SelectListItem { Text = x.roleId_name, Value = x.emp_localId }).ToList()); }