コード例 #1
0
    protected void btnAddToGroup_Click(object sender, EventArgs e)
    {
        IList <int> userIds = new List <int>();

        foreach (RepeaterItem item in this.rptAllGroup.Items)
        {
            HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox;
            if (chk != null)
            {
                if (chk.Checked)
                {
                    userIds.Add(int.Parse(chk.Value));
                }
            }
        }

        if (userIds.Count > 0)
        {
            int[] arrayIds = new int[userIds.Count];
            userIds.CopyTo(arrayIds, 0);
            using (_session = new Session())
            {
                UserGroup group = Magic.Sys.UserGroup.Retrieve(_session, this._groupId);
                try
                {
                    AuthorizationRepository repository = new AuthorizationRepository(_session);

                    repository.AddUsersToGroups(arrayIds, new UserGroup[] { group });

                    LoadUserInGroup();
                }
                catch (UnauthorizedException ex)
                {
                    WebUtil.ShowMsg(this, ex.Message, "警告");
                }
                catch (ApplicationException ex)
                {
                    WebUtil.ShowMsg(this, ex.Message, "提示");
                }
                catch (Exception ex)
                {
                    logger.Info("向用户组添加用户", ex);
                    WebUtil.ShowError(this, ex);
                }
            }
        }
    }