public static void EnsureDefaultRoles(this DTO.Permissions dto)
        {
            //Administrators Role always has implicit permissions, then it should be always in
            dto.EnsureRole(RoleController.Instance.GetRoleById(PortalSettings.Current.PortalId, PortalSettings.Current.AdministratorRoleId), true, true);

            //Show also default roles
            dto.EnsureRole(RoleController.Instance.GetRoleById(PortalSettings.Current.PortalId, PortalSettings.Current.RegisteredRoleId), false, true);
            dto.EnsureRole(new RoleInfo {
                RoleID = Int32.Parse(Globals.glbRoleAllUsers), RoleName = Globals.glbRoleAllUsersName
            }, false, true);
        }
 public static void EnsureRole(this DTO.Permissions dto, RoleInfo role, bool locked, bool isDefault)
 {
     if (dto.RolePermissions.All(r => r.RoleId != role.RoleID))
     {
         dto.RolePermissions.Add(new RolePermission
         {
             RoleId    = role.RoleID,
             RoleName  = role.RoleName,
             Locked    = locked,
             IsDefault = isDefault
         });
     }
 }
        public static void AddRolePermission(this DTO.Permissions dto, PermissionInfoBase permissionInfo)
        {
            var rolePermission = dto.RolePermissions.FirstOrDefault(p => p.RoleId == permissionInfo.RoleID);

            if (rolePermission == null)
            {
                rolePermission = new RolePermission
                {
                    RoleId   = permissionInfo.RoleID,
                    RoleName = permissionInfo.RoleName
                };
                dto.RolePermissions.Add(rolePermission);
            }

            if (rolePermission.Permissions.All(p => p.PermissionId != permissionInfo.PermissionID))
            {
                rolePermission.Permissions.Add(new Permission
                {
                    PermissionId   = permissionInfo.PermissionID,
                    PermissionName = permissionInfo.PermissionName,
                    AllowAccess    = permissionInfo.AllowAccess
                });
            }
        }
        public static void AddUserPermission(this DTO.Permissions dto, PermissionInfoBase permissionInfo)
        {
            var userPermission = dto.UserPermissions.FirstOrDefault(p => p.UserId == permissionInfo.UserID);

            if (userPermission == null)
            {
                userPermission = new UserPermission
                {
                    UserId      = permissionInfo.UserID,
                    DisplayName = permissionInfo.DisplayName
                };
                dto.UserPermissions.Add(userPermission);
            }

            if (userPermission.Permissions.All(p => p.PermissionId != permissionInfo.PermissionID))
            {
                userPermission.Permissions.Add(new Permission
                {
                    PermissionId   = permissionInfo.PermissionID,
                    PermissionName = permissionInfo.PermissionName,
                    AllowAccess    = permissionInfo.AllowAccess
                });
            }
        }
 public static void EnsureRole(this DTO.Permissions dto, RoleInfo role)
 {
     dto.EnsureRole(role, false);
 }
 public static void EnsureRole(this DTO.Permissions dto, RoleInfo role, bool locked)
 {
     dto.EnsureRole(role, locked, false);
 }