public static CampaignTrackingMetricVm[] FromCampaignTracking(Campaign campaign, CampaignTracking campaignTracking) { string filePathLive = $"{S3FileManager.ServerPrefix}{campaign.Assets.OpenModelImageFile}"; var metrics = new CampaignTrackingMetricVm[1] { new CampaignTrackingMetricVm { SFD_ID = campaign.Assets.SFDClientId, Client_ID = SfidLookup.GetCampaignName(campaign.Assets.SFDClientId), Campaign_Name = campaign.Approved.CampaignName, From_Line = campaign.Approved.FromLine, Subject_Line = campaign.Approved.SubjectLine, Deployment_Date = campaign.Approved.DeployDate?.ToString(StringConstants.DateFormatSlashes), Delivered = campaignTracking.Quantity, Open_Rate = campaignTracking.OpenedPercentage, Total_Opens = campaignTracking.Opened, Total_Clicks = campaignTracking.Clicked, Click_Percentage = campaignTracking.ClickedPercentage, HTML_CTR = campaignTracking.ClickToOpenPercentage, Mobile = campaignTracking.Mobile, Desktop = campaignTracking.Desktop, Image_URL = filePathLive } }; return(metrics); }
public static void Generate(System.Web.HttpResponseBase Response, Campaign campaign, CampaignTracking campaignTracking) { var metric = CampaignTrackingMetricVm.FromCampaignTracking(campaign, campaignTracking); var urls = CampaignTrackingMetricDetailVm.FromCampaignTracking(campaign, campaignTracking); ExcelPackage excel = new ExcelPackage(); var workSheet = excel.Workbook.Worksheets.Add("Strat Metrics"); workSheet.Cells[1, 1].LoadFromCollection(metric, true); workSheet.Cells[2, 8].Style.Numberformat.Format = "0.00%"; workSheet.Cells[2, 11].Style.Numberformat.Format = "0.00%"; workSheet.Cells[2, 12].Style.Numberformat.Format = "0.00%"; var workSheet2 = excel.Workbook.Worksheets.Add("Strat URLs"); workSheet2.Cells[1, 1].LoadFromCollection(urls, true); using (var memoryStream = new MemoryStream()) { string orderNumber = campaign.ReBroadcasted ? $"{campaign.ReBroadcastedOrderNumber}" : $"{campaign.OrderNumber}"; string fileName = $"{orderNumber}report.xlsx"; Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader($"content-disposition", $"attachment; filename={fileName}"); excel.SaveAs(memoryStream); memoryStream.WriteTo(Response.OutputStream); Response.Flush(); Response.End(); } }