protected void btnInsertEmail_Click(object sender, EventArgs e) { RadTextBox txtNameInsert = (RadTextBox)fvReport.FindControl("txtNameInsert"); RadTextBox txtAddressInsert = (RadTextBox)fvReport.FindControl("txtAddressInsert"); RadComboBox ddlNotifyOther = (RadComboBox)fvReport.FindControl("ddlNotifyOther"); RadioButtonList rblNotificationEmailStatusInsert = (RadioButtonList)fvReport.FindControl("rblNotificationEmailStatusInsert"); Label lblInsertEmailMessage = (Label)fvReport.FindControl("lblInsertEmailMessage"); 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."; } }
public void fvNotificationEmails_InsertItem() { try { TextBox txtNameInsert = (TextBox)fvNotificationEmails.FindControl("txtNameInsert"); TextBox txtAddressInsert = (TextBox)fvNotificationEmails.FindControl("txtAddressInsert"); RadioButtonList rblNotificationEmailStatusInsert = (RadioButtonList)fvNotificationEmails.FindControl("rblNotificationEmailStatusInsert"); Int16 statusId = Convert.ToInt16(rblNotificationEmailStatusInsert.SelectedValue); 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 = statusId; ctx.NotificationEmailAddresses.Add(newEmail); ctx.SaveChanges(); gvNotificationEmails.DataBind(); lblNotificationEmailMessage.Text = ""; } else { lblNotificationEmailMessage.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)) { lblNotificationEmailMessage.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)) { lblNotificationEmailMessage.Text = "A Notification Email already exists with this Name. Please enter a unique Name."; } else if (ctx.NotificationEmailAddresses.Any(x => x.Address == txtAddressInsert.Text)) { lblNotificationEmailMessage.Text = "A Notification Email already exists with this Email Address. Please enter a unique Email Address."; } } } } catch (Exception ex) { lblNotificationEmailMessage.Text = "Unable to add this Email Address. Please contact your system administrator."; } }