Пример #1
0
        public RoleValidatorMultiHost(RoleManagerMultiHost <TRole, TKey, TUserRole> manager)
            : base(manager)
        {
            Contract.Requires <ArgumentNullException>(manager != null, "manager");

            Manager = manager;
        }
Пример #2
0
        /// <summary>
        /// Returns true if the role exists
        /// </summary>
        /// <typeparam name="TRole">The type of the role.</typeparam>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <typeparam name="TUserRole">The type of the user role.</typeparam>
        /// <param name="manager">The manager.</param>
        /// <param name="hostId">The host identifier.</param>
        /// <param name="roleName">Name of the role.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">manager</exception>
        public static bool RoleExists <TRole, TKey, TUserRole>(this RoleManagerMultiHost <TRole, TKey, TUserRole> manager, TKey hostId, string roleName)
            where TKey : IEquatable <TKey>
            where TRole : IdentityRoleMultiHost <TKey, TUserRole>, IRoleMultiHost <TKey>, new()
            where TUserRole : IdentityUserRoleMultiHost <TKey>, IUserRoleMultiHost <TKey>, new()
        {
            Contract.Requires <ArgumentNullException>(manager != null, "manager");
            Contract.Requires <ArgumentNullException>(!hostId.Equals(default(TKey)), "hostId");
            Contract.Requires <ArgumentNullException>(!roleName.IsNullOrWhiteSpace(), "roleName");

            return(AsyncHelper.RunSync(() => manager.RoleExistsAsync(hostId, roleName)));
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RoleStoreMultiHost{TKey, TKey, TRole}" /> class.
        /// </summary>
        /// <param name="context">The <c>DbContext</c>.</param>
        /// <param name="hostId">The default host id to use when host id not specified.</param>
        /// <param name="systemHostId">The system host identifier (owns global users, roles, etc.)</param>
        public RoleStoreMultiHost(DbContext context, TKey systemHostId, TKey hostId)
            : base(context)
        {
            Contract.Requires <ArgumentNullException>(context != null, "context");
            Contract.Requires <ArgumentNullException>(!systemHostId.Equals(default(TKey)), "systemHostId");
            Contract.Requires <ArgumentNullException>(!hostId.Equals(default(TKey)), "hostId");

            this.SystemHostId = systemHostId;
            this.HostId       = hostId;
            this.RoleManager  = CreateRoleManager();
        }
Пример #4
0
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    this.Manager = null;

                    this.disposed = true;
                }
            }
        }
Пример #5
0
        /// <summary>
        ///     Create a role
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="role"></param>
        /// <returns></returns>
        public static IdentityResult Create <TRole, TKey, TUserRole>(this RoleManagerMultiHost <TRole, TKey, TUserRole> manager, string roleName, bool global = false)
            where TKey : IEquatable <TKey>
            where TRole : IdentityRoleMultiHost <TKey, TUserRole>, IRoleMultiHost <TKey>, new()
            where TUserRole : IdentityUserRoleMultiHost <TKey>, IUserRoleMultiHost <TKey>, new()
        {
            Contract.Requires <ArgumentNullException>(manager != null, "manager");
            Contract.Requires <ArgumentNullException>(!roleName.IsNullOrWhiteSpace(), "roleName");

            var hostId = global ? manager.SystemHostId : manager.HostId;

            return(AsyncHelper.RunSync(() => manager.CreateAsync(hostId, roleName, global)));
        }