/// <summary> /// 为一个用户分配分组 /// </summary> /// <param name="userId"></param> /// <param name="groupId"></param> public void SetUserGroup(string userId, int groupId) { using (UserGroupRepository groupRepository = new UserGroupRepository()) { UserGroup group = groupRepository.ExecuteConditions(g => g.Id == groupId). FirstOrDefault(); if (group == null) throw new Exception("指定分组不存在"); } using (UserRepository userRepository = new UserRepository()) { User user = userRepository.FindByID(userId); if (user == null) throw new Exception("用户不存在"); if (user.ApproveStatus == EnumUserApproveStatus.Approved) { user.ContentGroupId = groupId; userRepository.Update(user); } else { throw new Exception("当前用户还未通过审核,无法为其分配分组"); } } }