/// <summary> /// Load information of each email sent: device type, country, city, browser /// </summary> /// <param name="CampaignLogId"></param> /// <returns>mailTrackerLog</returns> public MailTrackerLog MailTrackerLogComponentByCampaignLogId(Guid CampaignLogId) { MailTrackerLog mailTrackerLog; if (CampaignLogId != Guid.Empty) { mifnexsoEntities = new MIFNEXSOEntities(); try { mailTrackerLog = mifnexsoEntities.MailTrackerLogs.FirstOrDefault(a => a.CampaingLogId == CampaignLogId); if (mailTrackerLog == null) { mailTrackerLog = new MailTrackerLog(); mailTrackerLog.MailTrackerLogId = Guid.Empty; mifnexsoEntities.MailTrackerLogs.AddObject(mailTrackerLog); } return(mailTrackerLog); } catch { return(null); } } else { return(null); } }
public MailTrackerLogComponent(Guid mailTrackerLogId) { if (mailTrackerLogId != Guid.Empty) { mifnexsoEntities = new MIFNEXSOEntities(); try { mailTrackerLog = mifnexsoEntities.MailTrackerLogs.FirstOrDefault(a => a.MailTrackerLogId == mailTrackerLogId); if (mailTrackerLog == null) { mailTrackerLog = new MailTrackerLog(); mailTrackerLog.MailTrackerLogId = Guid.Empty; mifnexsoEntities.MailTrackerLogs.AddObject(mailTrackerLog); } } catch (Exception) { throw; } } else { mailTrackerLog = new MailTrackerLog(); } }
public MailTrackerLogComponent() { mifnexsoEntities = new MIFNEXSOEntities(); mailTrackerLog = new MailTrackerLog(); mailTrackerLog.MailTrackerLogId = Guid.Empty; mifnexsoEntities.MailTrackerLogs.AddObject(mailTrackerLog); }
/// <summary> /// Campaign statistics per email status (Error, seen, sent) and country /// </summary> private void DataReportCampaign() { var listCampaignLog = CampaignLogComponent.GetCampaignLog(campaignId).ToList(); if (listCampaignLog.Count > 0) { //Separates campaign for creation date var listCampaignLogGroup = listCampaignLog.GroupBy(a => a.CreatedOn); var report = new List <ReportCampaign>(); foreach (var item in listCampaignLogGroup) { //Status var errors = item.Where(a => a.Status == "ERROR"); var viewMails = item.Where(a => a.Status == "READ"); var pendingViews = item.Where(a => a.Status == "SENT"); // calculate statistics emails seen decimal effectiveness = 0; if (viewMails.ToList().Count != 0) { effectiveness = Convert.ToDecimal(viewMails.ToList().Count) / Convert.ToDecimal(item.ToList().Count); } List <string> ListCountry = new List <string>(); foreach (var item2 in viewMails.ToList()) { MailTrackerLog mailTrackerLog = MailTrackerLogComponentByCampaignLogId(item2.CampaignLogId); if (mailTrackerLog != null) { ListCountry.Add(mailTrackerLog.Country); } } //calculate statistics per cuntry: total view and percentage var ListCountryGroup = ListCountry.GroupBy(a => a); List <GeographicView> viewGeographic = new List <GeographicView>(); foreach (var country in ListCountryGroup) { var viewsPercentage = (Convert.ToDecimal(country.Count()) / Convert.ToDecimal(item.Count())) * 100; var countryName = country.Key; if (string.IsNullOrEmpty(country.Key)) { countryName = "NULL"; } viewGeographic.Add(new GeographicView { Country = countryName, TotalViews = country.Count(), ViewsPercentage = decimal.Round(viewsPercentage, 2, MidpointRounding.AwayFromZero) }); } if (viewGeographic.Count == 0) { viewGeographic = null; } else { viewGeographic = viewGeographic.OrderByDescending(a => a.TotalViews).ToList(); } report.Add(new ReportCampaign { Created = Convert.ToDateTime(item.Key), SentMails = item.Count(), Errors = errors.Count(), BouncedMail = 0, ViewMails = viewMails.Count(), PendingViews = pendingViews.Count(), Effectiveness = decimal.Round(effectiveness, 2, MidpointRounding.AwayFromZero), ViewGeographic = viewGeographic }); } var list = report.OrderByDescending(a => a.Created).ToList(); if (report.Count >= 10) { list = report.OrderByDescending(a => a.Created).ToList().GetRange(0, 10); } rpReport.DataSource = list; rpReport.DataBind(); lblMessage.Visible = false; } else { lblMessage.Visible = true; } }