Esempio n. 1
0
        private RoleDto PopulatePermission(int applicationId, int roleId, List <int> fullaccessIds = null, List <int> readonlyaccessIds = null)
        {
            var searchApplicationRole = new ApplicationRoleSearchModel {
                ApplicationId = applicationId, RoleId = roleId, PageSize = int.MaxValue, SortColumn = "Id"
            };

            searchApplicationRole = _employeeFacadeApiClient.GetApplicationRoles(searchApplicationRole).Result;
            var menuItemSearch = new MenuItemSearchModel
            {
                PageSize      = int.MaxValue,
                SortColumn    = "DisplayName",
                ApplicationId = applicationId
            };

            menuItemSearch = _employeeFacadeApiClient.GetMenuItems(menuItemSearch).Result;
            var fullaccessPermissions            = searchApplicationRole.ApplicationRoleSearchResult.SelectMany(a => a.RolePermissions.Where(x => x.AccessLevel == AccessLevel.Full).Select(r => r.MenuItemId)).ToList();
            var readonlyPermissions              = searchApplicationRole.ApplicationRoleSearchResult.SelectMany(a => a.RolePermissions.Where(x => x.AccessLevel == AccessLevel.Readonly).Select(r => r.MenuItemId)).ToList();
            var menuItemsForAvailableForReadonly = menuItemSearch.MenuItemSearchResult.Where(x => !fullaccessPermissions.Contains(x.Id)).ToList();

            if (fullaccessIds != null)
            {
                menuItemsForAvailableForReadonly = menuItemsForAvailableForReadonly.Where(x => !fullaccessIds.Contains(x.Id)).ToList();
                fullaccessPermissions.AddRange(fullaccessIds);
            }
            var menuItemsForAvailableForFullaccess = menuItemSearch.MenuItemSearchResult.Where(x => !readonlyPermissions.Contains(x.Id)).ToList();

            if (readonlyaccessIds != null)
            {
                menuItemsForAvailableForFullaccess = menuItemsForAvailableForFullaccess.Where(x => !readonlyaccessIds.Contains(x.Id)).ToList();
                readonlyPermissions.AddRange(readonlyaccessIds);
            }
            var role = _employeeFacadeApiClient.GetRole(roleId).Result;

            role.ApplicationId = applicationId;
            role.Id            = roleId;
            role.ReadonlyPermisssionSelectList      = SelectedListHelper.GetPermissionSelectList(menuItemsForAvailableForReadonly, readonlyPermissions);
            role.FullAccessPermisssionSelectList    = SelectedListHelper.GetPermissionSelectList(menuItemsForAvailableForFullaccess, fullaccessPermissions);
            role.LinkedReadonlyRolePermissionsIds   = readonlyaccessIds?.Select(x => x.ToString()).ToList();
            role.LinkedFullAccessRolePermissionsIds = fullaccessIds?.Select(x => x.ToString()).ToList();
            return(role);
        }