protected void btnSubmit_Click(object sender, EventArgs e) { int result = 0; Subscriber subsriber = new Subscriber { EmailAddress = txtEmailAddress.Text, IsActive = true, CreatedAt = DateTime.Now, }; SubscriberCRUD subscriberCrud = new SubscriberCRUD(); Subscriber isExists = subscriberCrud.GetList() .Where(x => x.EmailAddress == txtEmailAddress.Text) .FirstOrDefault(); if (isExists == null) { result = subscriberCrud.Add(subsriber); } else if (!isExists.IsActive) { isExists.IsActive = !isExists.IsActive; subscriberCrud.Update(isExists); } if (result == -1) { Response.Redirect("~/Default.aspx?IsSuccess=SubscribeError"); } Response.Redirect("~/Default.aspx?IsSuccess=SubscribeSuccess"); }
public void SendSubscriptionEmail(Subscriber subscriber, string emailText, string subject) { if (subscriber == null) { return; } using (StreamReader strReader = new StreamReader(HttpContext.Current.Server.MapPath(@"~\Email\Template.html"))) { string emailTemplate = strReader.ReadToEnd(); emailTemplate = emailTemplate.Replace(Constants.EMAIL, emailText); emailTemplate = emailTemplate.Replace(Constants.UNSUBSCRIBE, Subscriber.GetSubscriberKey(subscriber)); strReader.Close(); SendEmail(smtpSection.Network.UserName, subscriber.EmailAddress, subject, emailTemplate); } }
public void btnSubmit_Click(object sender, EventArgs e) { Subscriber subscriber = new Subscriber(); SubscriberCRUD subscriberCrud = new SubscriberCRUD(); try { subscriber = new Subscriber() { Id = PageID, EmailAddress = txtEmail.Text, IsActive = Convert.ToBoolean(txtIsActive.Text), CreatedAt = Convert.ToDateTime(txtCreatedAt.Text), UpdatedAt = Convert.ToDateTime(txtUpdatedAt.Text) }; } catch (Exception ex) { ((BeMaster)Page.Master).ShowError(ex.Message); return; } subscriberCrud.Update(subscriber); Response.Redirect("~/BE/Subscribers.aspx"); }
public static string GetSubscriberKey(Subscriber subscriber) { var bytes = Encoding.UTF8.GetBytes( string.Format("{0}~{1}", subscriber.EmailAddress, subscriber.Id)); return Convert.ToBase64String(bytes); }