Example #1
0
        public static CampaignTrackingMetricDetailVm[] FromCampaignTracking(Campaign campaign, CampaignTracking campaignTracking)
        {
            var urls = new List <CampaignTrackingMetricDetailVm>();

            var proDatas = campaign.ProDatas
                           .Where(x => x.OrderNumber == campaignTracking.OrderNumber && x.SegmentNumber == campaignTracking.SegmentNumber)
                           .OrderByDescending(x => x.ClickCount);

            int index = 1;

            foreach (var proData in proDatas)
            {
                var model = new CampaignTrackingMetricDetailVm
                {
                    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),

                    URLS          = proData.Destination_URL,
                    Total_Clicks  = proData.ClickCount, //string.Format("{0:n0}", proData.ClickCount),
                    Unique_Clicks = proData.UniqueCnt,
                    Mobile_Clicks = proData.MobileCnt,
                    ID            = index++
                };

                urls.Add(model);
            }
            return(urls.ToArray());
        }
        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();
            }
        }