public IEnumerable <string> AnalyzeCampaign(string serviceProviderCampaignId, out int total) { SentToMembers analytics = mailChimpManager.GetReportSentTo(serviceProviderCampaignId); total = analytics.Total; return(analytics.Data.Select(c => c.Member.Email.ToString())); }
/// <summary> /// After confirmation send campaign /// </summary> public void SendCampaign() { if (ValidateFields()) { var confirmResult = MessageBox.Show("Do you want to send Campaign ?", "Send Campaign", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { string listId = string.Empty; string campaignId = cmbCampaign.SelectedValue.ToString(); CampaignFilter options = new CampaignFilter(); options.CampaignId = campaignId; // Loading panel Cursor.Current = Cursors.WaitCursor; try { //Send Campaign CampaignActionResult result = Manager.SendCampaign(campaignId); if (result.Complete) { if (chkEnableSMS.Checked) { bool flag = true; int count = 0; while (flag) { List <EmailParameter> emails = new List <EmailParameter>(); SentToLimits opt = new SentToLimits(); opt.Status = "sent"; opt.Start = count; opt.Limit = 100; bool isCampaignSend = false; while (!isCampaignSend) { CampaignFilter filter = new CampaignFilter(); filter.CampaignId = campaignId; //Get Sent Campaign CampaignListResult lists = Manager.GetCampaigns(filter); foreach (var l in lists.Data) { if (l.Status.Trim() == "sent") { isCampaignSend = true; SentToMembers results = Manager.GetReportSentTo(campaignId, opt); if (results.Data.Count == 0) { flag = false; break; } foreach (var i in results.Data) { string message = txtMessage.Text.Trim(); string phone = string.Empty; foreach (var j in i.Member.MemberMergeInfo) { if (message.IndexOf(j.Key.Trim()) != -1) { message = message.Replace("*|" + j.Key.Trim() + "|*", j.Value != null ? j.Value.ToString() : ""); } if (cmbFieldPhone.SelectedIndex > 0 && cmbFieldPhone.SelectedItem != null) { if (cmbFieldPhone.Text.Trim() == j.Key.ToString()) { if (j.Value != null && !string.IsNullOrEmpty(j.Value.ToString())) { phone = j.Value.ToString(); } } } } if (message.IndexOf("EMAIL") != -1) { message = message.Replace("*|EMAIL|*", i.Member.Email.ToString()); } if (!string.IsNullOrEmpty(phone)) { //Send SMS string smsResult = SmsSender.SendSMS(phone.Trim(), NexmoFromNumber, NexmoAPI, NexmoSecretKey, HttpUtility.UrlEncode(message)); } } break; } } } count++; } } } MessageBox.Show("Campaign sent successfully"); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Cursor.Current = Cursors.Default; } } } }