コード例 #1
0
        /// <summary>
        /// Inserts a entry in the AspNetUserRoles table.
        /// </summary>
        /// <param name="user">User to have role added.</param>
        /// <param name="roleName">Name of the role to be added to user.</param>
        /// <returns></returns>
        public Task AddToRoleAsync(TUser user, string roleName)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            if (string.IsNullOrEmpty(roleName))
            {
                throw new ArgumentException("Argument cannot be null or empty: roleName.");
            }

            string roleId = roleTable.GetRoleId(roleName);

            if (!string.IsNullOrEmpty(roleId))
            {
                userRolesTable.Insert(user, roleId);
            }

            return(Task.FromResult <object>(null));
        }
コード例 #2
0
        /// <summary>
        /// Inserts a entry in the AspNetUserRoles table.
        /// </summary>
        /// <param name="user">User to have role added.</param>
        /// <param name="roleName">Name of the role to be added to user.</param>
        /// <returns></returns>
        public Task AddToRoleAsync(IdentityUser user, String roleName)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (String.IsNullOrEmpty(roleName))
            {
                throw new ArgumentException("Argument cannot be null or empty: roleName.");
            }

            String roleId = _roleTable.GetRoleId(roleName);

            if (!String.IsNullOrEmpty(roleId))
            {
                _userRolesTable.Insert(user, roleId);
            }

            return(Task.FromResult <Object>(null));
        }