Beispiel #1
0
        protected void inviteButton_OnClick(object sender, EventArgs e)
        {
            List <SPUser> newUsers = IndividualsToInviteControl.WBxGetMultiResolvedUsers(SPContext.Current.Web);

            if (newUsers.Count == 0)
            {
                IndividualsToInviteFieldMessage.Text = "You must enter at least one individual to invite.";
                return;
            }

            List <String> newUsersNames = new List <String>();

            foreach (SPUser user in newUsers)
            {
                newUsersNames.Add(user.Name);
            }
            String newUsersString = String.Join(", ", newUsersNames.ToArray());

            if (!InviteAsMember.Checked && !InviteAsOwner.Checked)
            {
                ErrorText.Text = "You didn't select to invite as either a member or as an owner!";
                return;
            }

            String roleInTeam = "";

            if (InviteAsMember.Checked)
            {
                team.AddMembers(SPContext.Current.Site, newUsers);
                roleInTeam = "team member";
            }

            if (InviteAsOwner.Checked)
            {
                team.AddOwners(SPContext.Current.Site, newUsers);
                if (String.IsNullOrEmpty(roleInTeam))
                {
                    roleInTeam = "team owner";
                }
                else
                {
                    roleInTeam += " and team owner";
                }
            }
            Dictionary <String, String> textForTokens = new Dictionary <String, String>();

            textForTokens.Add("[ROLE_WITHIN_TEAM]", roleInTeam);

            if (SendInviteEmail.Checked)
            {
                String subjectTemplate = EmailSubject.Text;
                String bodyTemplate    = EmailBody.Text;

                if (SendAsOne.Checked)
                {
                    StringDictionary headers = new StringDictionary();

                    List <String> emailAddresses = new List <String>();
                    foreach (SPUser user in newUsers)
                    {
                        emailAddresses.Add(user.Email);
                    }

                    headers.Add("to", String.Join(";", emailAddresses.ToArray()));
                    headers.Add("content-type", "text/html"); //This is the default type, so isn't neccessary.

                    if (CCToYou.Checked)
                    {
                        headers.Add("cc", SPContext.Current.Web.CurrentUser.Email);
                    }

                    String subject = WBUtils.ProcessEmailTemplate(textForTokens, null, team, null, subjectTemplate, false);
                    String body    = WBUtils.ProcessEmailTemplate(textForTokens, null, team, null, bodyTemplate, true);

                    headers.Add("subject", subject);

                    WBUtils.SendEmail(SPContext.Current.Web, headers, body);
                }
                else
                {
                    foreach (SPUser user in newUsers)
                    {
                        StringDictionary headers = new StringDictionary();

                        headers.Add("to", user.Email);
                        headers.Add("content-type", "text/html"); //This is the default type, so isn't neccessary.

                        if (CCToYou.Checked)
                        {
                            headers.Add("cc", SPContext.Current.Web.CurrentUser.Email);
                        }

                        String subject = WBUtils.ProcessEmailTemplate(textForTokens, null, team, user, subjectTemplate, false);
                        String body    = WBUtils.ProcessEmailTemplate(textForTokens, null, team, user, bodyTemplate, true);

                        headers.Add("subject", subject);

                        WBUtils.SendEmail(SPContext.Current.Web, headers, body);
                    }
                }
            }

            CloseDialogAndRefresh("?panel=TeamDetails");
        }