private void InitObjects() { this.employeeInfoDAL = new EmployeeInfoDAL(this.SiteUrl); this.InitCurrentEmployeeInfoObject(); this.employeePositionDAL = new EmployeePositionDAL(this.SiteUrl); this.delegationModulesDAL = new DelegationModulesDAL(this.SiteUrl); this.delegationEmployeePositionsDAL = new DelegationEmployeePositionsDAL(this.SiteUrl); this.delegationsOfNewTaskDAL = new DelegationsOfNewTaskDAL(this.SiteUrl); this.delegationsDAL = new DelegationsDAL(this.SiteUrl); this.departmentDAL = new DepartmentDAL(this.SiteUrl); }
/// <summary> /// To check current employee who has delegation permission. /// </summary> /// <returns>If return true, current employee has delegation permission. Otherwise return false.</returns> public static bool DoesCurrentEmployeeHasDelegationPermission() { var res = false; // Administrator if (SPContext.Current.Web.CurrentUser.IsSiteAdmin) { res = true; } else // User { #region User if (delegationEmployeePositionsDAL == null) { delegationEmployeePositionsDAL = new DelegationEmployeePositionsDAL(SPContext.Current.Web.Url); } EmployeeInfo currentEmployeeInfo = HttpContext.Current.Session[StringConstant.EmployeeLogedin] as EmployeeInfo; //User is not common account, we should get from employee list if (currentEmployeeInfo == null) { SPUser spUser = SPContext.Current.Web.CurrentUser; if (spUser != null) { EmployeeInfoDAL employeeInfoDAL = new EmployeeInfoDAL(SPContext.Current.Web.Url); currentEmployeeInfo = employeeInfoDAL.GetByADAccount(spUser.ID); //HttpContext.Current.Session[StringConstant.EmployeeLogedin] = currentEmployeeInfo; } } if (currentEmployeeInfo != null) { if (currentEmployeeInfo.EmployeePosition != null) { var employeePositionId = currentEmployeeInfo.EmployeePosition.LookupId; var delegationEmployeePositions = delegationEmployeePositionsDAL.GetByEmployeePosition(employeePositionId); if (delegationEmployeePositions != null && delegationEmployeePositions.Count > 0) { res = true; } } } #endregion } return(res); }
/// <summary> /// To check current employee who has approval delegation permission. /// </summary> /// <returns>If return true, current employee has approval delegation permission. Otherwise return false.</returns> public static bool DoesCurrentEmployeeHasApprovalPermission() { var res = false; if (delegationEmployeePositionsDAL == null) { delegationEmployeePositionsDAL = new DelegationEmployeePositionsDAL(SPContext.Current.Web.Url); } EmployeeInfo currentEmployeeInfo = HttpContext.Current.Session[StringConstant.EmployeeLogedin] as EmployeeInfo; //User is not common account, we should get from employee list if (currentEmployeeInfo == null) { SPUser spUser = SPContext.Current.Web.CurrentUser; if (spUser != null) { EmployeeInfoDAL employeeInfoDAL = new EmployeeInfoDAL(SPContext.Current.Web.Url); currentEmployeeInfo = employeeInfoDAL.GetByADAccount(spUser.ID); //HttpContext.Current.Session[StringConstant.EmployeeLogedin] = currentEmployeeInfo; } } if (currentEmployeeInfo != null) { if (currentEmployeeInfo.EmployeePosition != null) { var employeePositionId = currentEmployeeInfo.EmployeePosition.LookupId; string queryString = $@"<Where> <Eq> <FieldRef Name='{StringConstant.DelegationEmployeePositionsList.Fields.DelegatedEmployeePositions}' LookupId='TRUE'/> <Value Type='Lookup'>{employeePositionId}</Value> </Eq> </Where>"; SPQuery query = new SPQuery { Query = queryString, RowLimit = 1 }; var delegationEmployeePositions = delegationEmployeePositionsDAL.GetByQuery(query); if (delegationEmployeePositions != null && delegationEmployeePositions.Count > 0) { res = true; } else // Look up Delegated by: { var delegatedByPositionIds = currentEmployeeInfo.DelegatedBy.Select(x => x.LookupId); foreach (var delegatedByPositionId in delegatedByPositionIds) { queryString = $@"<Where> <Eq> <FieldRef Name='{StringConstant.DelegationEmployeePositionsList.Fields.EmployeePosition}' LookupId='TRUE'/> <Value Type='Lookup'>{delegatedByPositionId}</Value> </Eq> </Where>"; query = new SPQuery { Query = queryString, RowLimit = 1 }; delegationEmployeePositions = delegationEmployeePositionsDAL.GetByQuery(query); if (delegationEmployeePositions != null && delegationEmployeePositions.Count > 0) { return(true); } } } } if (currentEmployeeInfo.DelegatedBy != null && currentEmployeeInfo.DelegatedBy.Count > 0) { res = true; } } return(res); }