Ejemplo n.º 1
0
        /// <summary>
        /// 设置/取消 群组管理员
        /// </summary>
        /// <param name="groupId">群组Id</param>
        /// <param name="userId">用户Id</param>
        /// <param name="isManager">是否管理员</param>
        public bool SetManager(long groupId, long userId, bool isManager)
        {
            //设计要点:
            //1、userId必须是groupId成员
            GroupMember member = groupMemberRepository.GetMember(groupId, userId);

            if (member == null)
            {
                return(false);
            }
            if (member.IsManager == isManager)
            {
                return(false);
            }
            member.IsManager = isManager;
            groupMemberRepository.Update(member);
            if (isManager)
            {
                EventBus <GroupMember> .Instance().OnAfter(member, new CommonEventArgs(EventOperationType.Instance().SetGroupManager()));
            }
            else
            {
                EventBus <GroupMember> .Instance().OnAfter(member, new CommonEventArgs(EventOperationType.Instance().CancelGroupManager()));
            }
            return(true);
        }
Ejemplo n.º 2
0
        public void ChangeMemberRole(GroupMemberViewModel viewModel)
        {
            string userRole = _groupMemberRepository.GetRole(viewModel.GroupId, viewModel.CurrentUserId);

            if (userRole.Equals(RoleNames.ROLE_OWNER) &&
                _groupMemberRepository.IsInGroup(viewModel.GroupId, viewModel.UserId))
            {
                var groupMember = _groupMemberRepository.Get(u => u.GroupId == viewModel.GroupId && u.UserId == viewModel.UserId).Single();

                groupMember.RoleId = viewModel.RoleId;
                _groupMemberRepository.Update(groupMember);
            }
            else
            {
                throw new ArgumentException("User does not belong to this group");
            }
        }