protected void btnInsertEmail_Click(object sender, EventArgs e)
        {
            try
            {
                using (FormContext ctx = new FormContext())
                {
                    if (!ctx.NotificationEmailAddresses.Any(x => x.Name == txtNameInsert.Text || x.Address == txtAddressInsert.Text))
                    {
                        if (!ctx.SystemUsers.Any(x => x.EmailAddress == txtAddressInsert.Text))
                        {
                            NotificationEmailAddress newEmail = new NotificationEmailAddress();

                            newEmail.Timestamp = DateTime.Now;
                            newEmail.Name      = txtNameInsert.Text;
                            newEmail.Address   = txtAddressInsert.Text;
                            newEmail.Status    = Convert.ToInt16(rblNotificationEmailStatusInsert.SelectedValue);

                            ctx.NotificationEmailAddresses.Add(newEmail);

                            ctx.SaveChanges();

                            lblInsertEmailMessage.Text = "";
                            txtAddressInsert.Text      = "";
                            txtNameInsert.Text         = "";
                            rblNotificationEmailStatusInsert.SelectedIndex = 0;
                            ddlNotifyOther.DataBind();
                        }
                        else
                        {
                            lblInsertEmailMessage.Text = "A System User already exists with this Email Address.  Please enter a unique Email Address.";
                        }
                    }
                    else
                    {
                        if (ctx.NotificationEmailAddresses.Any(x => x.Name == txtNameInsert.Text && x.Address == txtAddressInsert.Text))
                        {
                            lblInsertEmailMessage.Text = "A Notification Email already exists with this Name and Email Address.  Please enter a unique Name and Email Address.";
                        }
                        else if (ctx.NotificationEmailAddresses.Any(x => x.Name == txtNameInsert.Text))
                        {
                            lblInsertEmailMessage.Text = "A Notification Email already exists with this Name.  Please enter a unique Name.";
                        }
                        else if (ctx.NotificationEmailAddresses.Any(x => x.Address == txtAddressInsert.Text))
                        {
                            lblInsertEmailMessage.Text = "A Notification Email already exists with this Email Address.  Please enter a unique Email Address.";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                lblInsertEmailMessage.Text = "Unable to add this Email Address.  Please contact your system administrator.";
            }
        }
Ejemplo n.º 2
0
        public static NotificationEmailModel ToNotificationEmail(this EmailMessage emailMessage,
                                                                 string configuredFromAddress)
        {
            var fromEmail = string.IsNullOrEmpty(emailMessage.From) ? configuredFromAddress : emailMessage.From;

            NotificationEmailAddress from = ToNotificationAddress(fromEmail);

            return(new NotificationEmailModel(from,
                                              GetNotificationAddresses(emailMessage.To),
                                              GetNotificationAddresses(emailMessage.Cc),
                                              GetNotificationAddresses(emailMessage.Bcc),
                                              GetNotificationAddresses(emailMessage.ReplyTo),
                                              emailMessage.Subject,
                                              emailMessage.Body,
                                              emailMessage.Attachments,
                                              emailMessage.IsBodyHtml));
        }
Ejemplo n.º 3
0
        private static IEnumerable <NotificationEmailAddress> GetNotificationAddresses(IEnumerable <string> addresses)
        {
            if (addresses is null)
            {
                return(null);
            }

            var notificationAddresses = new List <NotificationEmailAddress>();

            foreach (var address in addresses)
            {
                NotificationEmailAddress notificationAddress = ToNotificationAddress(address);
                if (notificationAddress is not null)
                {
                    notificationAddresses.Add(notificationAddress);
                }
            }

            return(notificationAddresses);
        }