示例#1
0
 void UserInRole_After(UserInRole sender, CommonEventArgs eventArgs)
 {
     RoleService roleService = new RoleService();
     var role = roleService.Get(sender.RoleName);
     if (role == null)
         return;
     NoticeService noticeService = Tunynet.DIContainer.Resolve<NoticeService>();
     Notice notice = Notice.New();
     notice.UserId = sender.UserId;
     notice.TypeId = NoticeTypeIds.Instance().Hint();
     notice.TemplateName = "RoleAdd";
     notice.RelativeObjectName = role.FriendlyRoleName;
     noticeService.Create(notice);
 }
示例#2
0
        /// <summary>
        /// 移除用户的一个角色
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="roleName">角色名称</param>
        public void RemoveUserFromRole(long userId, string roleName)
        {
            Role role = Get(roleName);

            if (role != null)
            {
                UserInRole userInRole = new UserInRole()
                {
                    UserId   = userId,
                    RoleName = role.RoleName
                };

                userInRoleRepository.Delete(userId, roleName);

                EventBus <UserInRole> .Instance().OnAfter(userInRole, new CommonEventArgs(EventOperationType.Instance().Delete()));
            }
        }
示例#3
0
        /// <summary>
        /// 给用户添加角色
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="roleName">角色名称</param>
        public void AddUserToRole(long userId, string roleName)
        {
            Role role = Get(roleName);
            if (role != null)
            {
                if (!role.ConnectToUser)
                    return;

                UserInRole userInRole = new UserInRole()
                {
                    UserId = userId,
                    RoleName = role.RoleName
                };

                userInRoleRepository.Insert(userInRole);

                EventBus<UserInRole>.Instance().OnAfter(userInRole, new CommonEventArgs(EventOperationType.Instance().Create()));
            }
        }
示例#4
0
        /// <summary>
        /// 给用户添加角色
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="roleName">角色名称</param>
        public void AddUserToRole(long userId, string roleName)
        {
            Role role = Get(roleName);

            if (role != null)
            {
                if (!role.ConnectToUser)
                {
                    return;
                }

                UserInRole userInRole = new UserInRole()
                {
                    UserId   = userId,
                    RoleName = role.RoleName
                };

                userInRoleRepository.Insert(userInRole);

                EventBus <UserInRole> .Instance().OnAfter(userInRole, new CommonEventArgs(EventOperationType.Instance().Create()));
            }
        }
示例#5
0
        /// <summary>
        /// 移除用户的一个角色
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="roleName">角色名称</param>
        public void RemoveUserFromRole(long userId, string roleName)
        {
            Role role = Get(roleName);
            if (role != null)
            {
                UserInRole userInRole = new UserInRole()
                {
                    UserId = userId,
                    RoleName = role.RoleName
                };

                userInRoleRepository.Delete(userId, roleName);

                EventBus<UserInRole>.Instance().OnAfter(userInRole, new CommonEventArgs(EventOperationType.Instance().Delete()));
            }
        }