CAESDO.Recruitment.Web.Authorized_EmailTemplates.btnSendTemplate_Click C# (CSharp) Метод

btnSendTemplate_Click() защищенный Метод

Send an email to the checked applicants based on whatever template is currently selected (in txtEmailTemplate)
protected btnSendTemplate_Click ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
Результат void
        protected void btnSendTemplate_Click(object sender, EventArgs e)
        {
            StringBuilder errorEmails = new StringBuilder();

            var bccAddress = txtBccAddress.Text;

            //Go through each of the applications
            foreach (var row in lviewApplications.Items)
            {
                CheckBox cEmail = (CheckBox)row.FindControl("chkEmailApplicant");

                if (cEmail.Checked) //Should we send to this applicant?
                {
                    //Get the user and email them
                    int userID = (int)lviewApplications.DataKeys[row.DataItemIndex]["id"];
                    Application selectedApplication = ApplicationBLL.GetByID(userID);

                    var bodyFromTemplate = new TemplateProcessing().ProcessTemplate(null, selectedApplication,
                                                                                    txtEmailTemplate.Text,
                                                                                    false);

                    bool success = MessageBLL.SendMessage(WebConfigurationManager.AppSettings["emailFromEmail"],
                                                            selectedApplication.Email,
                                                            bccAddress,
                                                            "UC Davis Recruitment Message",
                                                            bodyFromTemplate);

                    if (success == false) errorEmails.AppendFormat("{0}, ", selectedApplication.Email);
                }
            }

            //Notify the user of the message results
            if (errorEmails.Length != 0)
            {
                errorEmails.Remove(errorEmails.Length - 2, 2);
                lblSentEmail.Text = string.Format("Could not send email to the following address(es): {0}", errorEmails.ToString());
            }
            else
            {
                lblSentEmail.Text = "Email(s) sent successfully";
            }
        }