Example #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);
 }
Example #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()));
            }
        }
Example #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()));
            }
        }
Example #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()));
            }
        }
Example #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()));
            }
        }