public static void PopulateFakeData(WfpictContext db, Campaign campaign, string orderNumber, string UploadPath)
        {
            // Process Links file
            string filePath = Path.Combine(UploadPath, campaign.Assets.OpenModelLinksFile);

            S3FileManager.Download(campaign.Assets.OpenModelLinksFile, filePath);
            List <string> links = CsvReader.ReadCsv(filePath);

            PopulateFakeData(db, campaign, orderNumber, links);
        }
예제 #2
0
        // Creative
        public ActionResult Index(Guid id)
        {
            var campaign = Db.Campaigns
                           .Include(c => c.Assets)
                           .Include(c => c.Testing)
                           .Include(c => c.Approved)
                           .Include(c => c.Creative)
                           .FirstOrDefault(c => c.Id == id);

            Session["id"]          = id;
            Session["OrderNumber"] = campaign.OrderNumber;

            var creative = new CreativeVm()
            {
                CampaignId   = campaign.Id.ToString(),
                OrderNumber  = campaign.OrderNumber,
                CampaignName = campaign.Testing.CampaignName,
                FromLine     = campaign.Testing.FromLine,
                SubjectLine  = campaign.Testing.SubjectLine,
                TestSeedFile = campaign.Assets.TestSeedFile,
                LiveSeedFile = campaign.Assets.LiveSeedFile,
                Creatives    = campaign.Creative?.CreativeHtml,
                TestEmails   = new List <SelectItemPair>(),
                LiveEmails   = new List <SelectItemPair>()
            };

            if (!string.IsNullOrEmpty(campaign.Assets.TestSeedFile))
            {
                string filePath = Path.Combine(UploadPath, campaign.Assets.TestSeedFile);
                if (!System.IO.File.Exists(filePath) && !string.IsNullOrEmpty(campaign.Assets.TestSeedFile))
                {
                    S3FileManager.Download(campaign.Assets.TestSeedFile, filePath);
                }
                creative.TestEmails = CreativeHelper.ReadEmails(filePath);
            }

            if (!string.IsNullOrEmpty(campaign.Assets.LiveSeedFile))
            {
                string filePathLive = Path.Combine(UploadPath, campaign.Assets.LiveSeedFile);
                if (!System.IO.File.Exists(filePathLive) && !string.IsNullOrEmpty(campaign.Assets.LiveSeedFile))
                {
                    S3FileManager.Download(campaign.Assets.LiveSeedFile, filePathLive);
                }
                creative.LiveEmails = CreativeHelper.ReadEmails(filePathLive);
            }

            Session["TestSeedFile"] = campaign.Assets.TestSeedFile;
            Session["TestSeedUrl"]  = campaign.Assets.TestSeedUrl;
            Session["LiveSeedFile"] = campaign.Assets.LiveSeedFile;
            Session["LiveSeedUrl"]  = campaign.Assets.LiveSeedUrl;
            return(View(creative));
        }
예제 #3
0
        public ActionResult DownloadFile(UploadFileVm fileVm)
        {
            string filePath = Path.Combine(UploadPath, fileVm.FileName);

            if (fileVm.FileType == "CompanyLogo")
            {
                filePath = Path.Combine(ImagesPath, fileVm.FileName);
            }
            else if (IsUseS3)
            {
                S3FileManager.Download(fileVm.FileName, filePath);
            }
            return(File(filePath, "text/csv", fileVm.FileName));
        }
예제 #4
0
        private static List <string> ProcessZipFile(WfpictContext db, string uploadPath, string zipCodeFile, string orderNumber)
        {
            string zipFilePath = Path.Combine(uploadPath, zipCodeFile);

            S3FileManager.Download(zipCodeFile, zipFilePath);
            var list = new List <string>();

            foreach (var line in File.ReadAllLines(zipFilePath))
            {
                var trimmed = StringHelper.Trim(line);
                if (string.IsNullOrEmpty(trimmed))
                {
                    continue;
                }
                list.Add(trimmed);
            }
            LogHelper.AddLog(db, LogType.DataProcessing, orderNumber, $"ZipCodeFile {zipCodeFile} processed sucessfully.");
            return(list);
        }
예제 #5
0
        public static ClickMeterLink ProcessLinksFile(string uploadPath, string orderNumber, string campaignName, string ezLinksFile)
        {
            string linkName     = $"{orderNumber}links";
            var    linksWeights = new List <DestinationItem>();

            try
            {
                string ezLinksFilePath = Path.Combine(uploadPath, ezLinksFile);
                S3FileManager.Download(ezLinksFile, ezLinksFilePath);
                foreach (var line in System.IO.File.ReadAllLines(ezLinksFilePath))
                {
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }
                    var links = line.Split(",".ToCharArray());
                    if (links.Length != 2)
                    {
                        continue;
                    }
                    int w8 = 0;
                    int.TryParse(links[1], out w8);
                    var lw = new DestinationItem()
                    {
                        url = links[0], weight = w8
                    };
                    linksWeights.Add(lw);
                }
            }
            catch (Exception ex)
            {
                throw new AdsException("There is some issue in processing links file.");
            }

            int sum = linksWeights.Sum(x => x.weight);

            if (sum != 100)
            {
                throw new AdsException("Click Meter Links wieght must sum upto 100. (" + sum + ")");
            }

            return(CreateCampaignWithRotatorLink(orderNumber, campaignName, linkName, linksWeights.ToArray()));
        }
        public static List <DynamicCodingInput> LoadLookupInput(string uploadPath, string dynamicCodingFile)
        {
            List <DynamicCodingInput> inputs = new List <DynamicCodingInput>();
            string dyanmicFilePath           = System.IO.Path.Combine(uploadPath, dynamicCodingFile);

            S3FileManager.Download(dynamicCodingFile, dyanmicFilePath);

            try
            {
                bool isFirstHeader = true;
                foreach (var line in System.IO.File.ReadAllLines(dyanmicFilePath))
                {
                    if (isFirstHeader)
                    {
                        isFirstHeader = false; continue;
                    }

                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    string[] trimmedCells = line.Split(",".ToCharArray());
                    if (trimmedCells.Length != 3 || NumberHelper.Parse(trimmedCells[2]) == -1)
                    {
                        continue;
                    }

                    inputs.Add(new DynamicCodingInput()
                    {
                        OrignalURL = trimmedCells[0],
                        URLType    = trimmedCells[1],
                        Qunatity   = Int32.Parse(trimmedCells[2])
                    });
                }
                return(inputs);
            }
            catch (Exception ex)
            {
                throw new AdsException("There is something wrong with Dynamic Coding File. Please upload correct one." + ex.Message);
            }
        }
예제 #7
0
        public static List <SelectListItem> GetZipCodes(string uploadPath, string zipCodeFile)
        {
            string zipFilePath = Path.Combine(uploadPath, zipCodeFile);

            S3FileManager.Download(zipCodeFile, zipFilePath);
            var zipCodes = new List <SelectListItem>();

            foreach (var line in System.IO.File.ReadAllLines(zipFilePath))
            {
                var trimmed = StringHelper.Trim(line);
                if (string.IsNullOrEmpty(trimmed))
                {
                    continue;
                }
                zipCodes.Add(new SelectListItem()
                {
                    Text = trimmed, Value = trimmed
                });
            }
            return(zipCodes);
        }
        public ActionResult SaveInput(OpenModelInputVm vm)
        {
            if (ModelState.IsValid)
            {
                Campaign campaign = Db.Campaigns
                                    .Include(x => x.Assets)
                                    .FirstOrDefault(x => x.Id.ToString() == vm.Id);

                campaign.Assets.OpenModelLinksFile = vm.OpenModelLinksFile;
                campaign.Assets.OpenModelImageFile = vm.OpenModelImageFile;
                if (!string.IsNullOrEmpty(vm.SFDClientId))
                {
                    campaign.Assets.SFDClientId = int.Parse(vm.SFDClientId);
                }

                if (!string.IsNullOrEmpty(campaign.Assets.OpenModelLinksFile))
                {
                    string filePath = Path.Combine(UploadPath, campaign.Assets.OpenModelLinksFile);
                    S3FileManager.Download(campaign.Assets.OpenModelLinksFile, filePath);
                    List <string> links = CsvReader.ReadCsv(filePath);
                    campaign.Assets.OpenModelLinksCount = links.Count;
                }
                Db.SaveChanges();

                TempData["Success"] = "Reporting Model Input data saved successfully!";
                return(RedirectToAction("View", "OpenModel", new { id = vm.Id }));
            }
            else
            {
                var errorList = (from item in ModelState.Values
                                 from error in item.Errors
                                 select error.ErrorMessage).ToList();
                TempData["Error"] = "There is error in saving data." + string.Join("<br/>", errorList);
            }
            return(View("OpenModelInput", vm));
        }
예제 #9
0
        public ActionResult EditTesting([Bind(Include =
                                                  "Assets,Segments,Id,CampaignId,OrderNumber,CampaignName,WhiteLabel,ReBroadCast,ReBroadcastDate,FromLine,SubjectLine,HtmlImageFiles,CreativeURL,TestSeedList,FinalSeedList,IsTested,TestingTime,TestingUrgency,DeployDate,ZipCodeFile,ZipURL,GeoDetails,Demographics,Quantity,SpecialInstructions,CreatedAt,CreatedBy,IsOpenPixel,OpenPixelUrl,BannerUrl,OpenGoals,ClickGoals,DataFileQuantity,DataFileUrl,DateFetched,IsOmniOrder,OmniDeployDate,Impressions,ChannelTypes,PaceDays,IsDynamicCoding,DynamicCodingFile,OpenModelLinksFile,OpenModelLinksCount,OpenModelImageFile,SFDClientId,ClickMeterGroupId,ClickMeterRotatorLinkId,ClickMeterRotatorLink,EzStates,EzDMAs,EzLinksFile"
                                              )] CampaignTestingVm campaignTestingVm)
        {
            if (ModelState.IsValid)
            {
                // Updatin Testing
                TinyMapper.Bind <CampaignTestingVm, CampaignTesting>(config =>
                {
                    config.Ignore(x => x.ChannelTypes);
                    config.Ignore(x => x.Assets);
                    config.Ignore(x => x.Segments);
                });
                var campaignTesting = TinyMapper.Map <CampaignTesting>(campaignTestingVm);
                campaignTesting.ChannelTypes = campaignTestingVm.ChannelTypes == null ? null :
                                               string.Join(",", campaignTestingVm.ChannelTypes);
                Db.Entry(campaignTesting).State = EntityState.Modified;
                Db.SaveChanges();

                // Updatin Asssets
                var campaignAssets = Db.CampaignAssets.FirstOrDefault(x => x.CampaignId == campaignTestingVm.CampaignId);
                campaignAssets.CreativeFiles      = campaignTestingVm.Assets.CreativeFiles;
                campaignAssets.CreativeUrl        = campaignTestingVm.Assets.CreativeUrl;
                campaignAssets.ZipCodeFile        = campaignTestingVm.Assets.ZipCodeFile;
                campaignAssets.ZipCodeUrl         = campaignTestingVm.Assets.ZipCodeUrl;
                campaignAssets.TestSeedFile       = campaignTestingVm.Assets.TestSeedFile;
                campaignAssets.LiveSeedFile       = campaignTestingVm.Assets.LiveSeedFile;
                campaignAssets.OpenModelLinksFile = campaignTestingVm.OpenModelLinksFile;
                campaignAssets.OpenModelImageFile = campaignTestingVm.OpenModelImageFile;
                if (!string.IsNullOrEmpty(campaignTestingVm.SFDClientId))
                {
                    campaignAssets.SFDClientId = int.Parse(campaignTestingVm.SFDClientId);
                }
                if (!string.IsNullOrEmpty(campaignAssets.OpenModelLinksFile) && campaignAssets.OpenModelLinksCount == 0)
                {
                    string filePath = Path.Combine(UploadPath, campaignAssets.OpenModelLinksFile);
                    S3FileManager.Download(campaignAssets.OpenModelLinksFile, filePath);
                    List <string> links = CsvReader.ReadCsv(filePath);
                    campaignAssets.OpenModelLinksCount = links.Count;
                }
                Db.Entry(campaignAssets).State = EntityState.Modified;
                Db.SaveChanges();

                // Updating Segments
                if (campaignTestingVm.Segments != null)
                {
                    foreach (var segmentVm in campaignTestingVm.Segments)
                    {
                        var segment = Db.CampaignSegments.FirstOrDefault(x => x.Id == segmentVm.Id);
                        if (segment == null)
                        {
                            segment = new CampaignSegment()
                            {
                                Id            = Guid.NewGuid(),
                                CreatedAt     = DateTime.Now,
                                CampaignId    = campaignTestingVm.CampaignId,
                                OrderNumber   = campaignTestingVm.OrderNumber,
                                SegmentNumber = segmentVm.SegmentNumber
                            };
                            Db.CampaignSegments.Add(segment);
                            Db.SaveChanges();
                        }
                        segment.SubjectLine      = segmentVm.SubjectLine;
                        segment.FromLine         = segmentVm.FromLine;
                        segment.WhiteLabel       = segmentVm.WhiteLabel;
                        segment.Quantity         = segmentVm.Quantity;
                        segment.DeploymentDate   = segmentVm.DeploymentDate;
                        segment.CreativeFiles    = segmentVm.CreativeFiles;
                        segment.FirstRangeStart  = segmentVm.FirstRangeStart;
                        segment.FirstRangeEnd    = segmentVm.FirstRangeEnd;
                        segment.SecondRangeStart = segmentVm.SecondRangeStart;
                        segment.SecondRangeEnd   = segmentVm.SecondRangeEnd;
                        segment.ThirdRangeStart  = segmentVm.ThirdRangeStart;
                        segment.ThirdRangeEnd    = segmentVm.ThirdRangeEnd;
                        Db.Entry(segment).State  = EntityState.Modified;
                        Db.SaveChanges();
                    }
                }

                TempData["Success"] = "Testing data saved successfully!";
                return(RedirectToAction("EditTesting", "Testing", new { id = campaignTestingVm.Id }));
            }
            else
            {
                var errorList = (from item in ModelState.Values
                                 from error in item.Errors
                                 select error.ErrorMessage).ToList();
                TempData["Error"] = "There is error in saving data." + string.Join("<br/>", errorList);
            }

            ViewBag.TestingUrgency = new SelectList(EnumHelper.GetEnumTextValues(typeof(TestingUrgency)), "Value",
                                                    "Text", campaignTestingVm.TestingUrgency);
            ViewBag.WhiteLabel          = new SelectList(CustomersWithWLList, "Value", "Text", campaignTestingVm.WhiteLabel);
            ViewBag.SfidClientCampaigns = new SelectList(SfidClientCampaigns, "Value", "Text", campaignTestingVm.SFDClientId);
            ViewBag.StateList           = new SelectList(States, "Value", "Text", campaignTestingVm.EzStates);
            ViewBag.DmaList             = new SelectList(DmaLookup.US.Select(
                                                             x => new SelectListItem()
            {
                Text  = x.code + " - " + x.area,
                Value = x.code
            }).ToList(), "Value", "Text", campaignTestingVm.EzDMAs);

            string view = IsNxs ? "EditTestingNXS" : "EditTesting";

            return(View(view, campaignTestingVm));
        }
예제 #10
0
        public static void ProcessAssetUpdateUrls(string uploadPath, string orderNumber)
        {
            using (var db = new WfpictContext())
            {
                var campaign = db.Campaigns.Include(x => x.Assets).FirstOrDefault(x => x.OrderNumber == orderNumber);

                var directory = $"{uploadPath}\\{campaign.OrderNumber}";
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                // HtmlImagesURL
                try
                {
                    if (!string.IsNullOrEmpty(campaign.Assets.CreativeFiles))
                    {
                        string filePath = Path.Combine(uploadPath, campaign.Assets.CreativeFiles);
                        S3FileManager.Download(campaign.Assets.CreativeFiles, filePath);
                        var result = FileManager.ProcessHtmlZip(uploadPath, filePath, campaign.OrderNumber, campaign.IsAddOptOut, campaign.IsAddViewInBrowser);
                        campaign.Assets.CreativeUrl    = result.FilePathLive;
                        campaign.Assets.CreativeStatus = (int)result.Status;
                        LogHelper.AddLog(db, LogType.FileProcessing, orderNumber, "CreativeFiles processed: " + campaign.Assets.CreativeUrl + ", Status: " + System.Enum.GetName(typeof(UploadFileStatus), campaign.Assets.CreativeStatus));
                    }
                }
                catch (Exception ex)
                {
                    campaign.Assets.CreativeStatus = (int)UploadFileStatus.Failed;
                    LogHelper.AddError(db, LogType.FileProcessing, orderNumber, "CreativeFiles processing failed, " + ex.Message + ", Status: " + System.Enum.GetName(typeof(UploadFileStatus), campaign.Assets.CreativeStatus));
                }
                db.SaveChanges();

                if (!string.IsNullOrEmpty(campaign.Assets.ZipCodeFile))
                {
                    campaign.Assets.ZipCodeUrl = FileManager.GetFilePathLive(UploadFileType.ZipFile,
                                                                             campaign.OrderNumber);
                    campaign.Assets.ZipCodeStatus = (int)UploadFileStatus.Completed;
                    LogHelper.AddLog(db, LogType.FileProcessing, orderNumber,
                                     "ZipCodeFile processed: " + campaign.Assets.ZipCodeUrl + ", Status: " +
                                     System.Enum.GetName(typeof(UploadFileStatus), campaign.Assets.ZipCodeStatus));
                }

                // TestSeedList
                if (!string.IsNullOrEmpty(campaign.Assets.TestSeedFile))
                {
                    campaign.Assets.TestSeedUrl = FileManager.GetFilePathLive(UploadFileType.TestSeedFile,
                                                                              campaign.OrderNumber);
                    campaign.Assets.TestSeedStatus = (int)UploadFileStatus.Completed;
                    LogHelper.AddLog(db, LogType.FileProcessing, orderNumber,
                                     "TestSeedFile processed: " + campaign.Assets.TestSeedUrl + ", Status: " +
                                     System.Enum.GetName(typeof(UploadFileStatus), campaign.Assets.TestSeedStatus));
                }

                // Final SeedList
                if (!string.IsNullOrEmpty(campaign.Assets.LiveSeedFile))
                {
                    campaign.Assets.LiveSeedUrl = FileManager.GetFilePathLive(UploadFileType.LiveSeedFile,
                                                                              campaign.OrderNumber);
                    campaign.Assets.LiveSeedStatus = (int)UploadFileStatus.Completed;
                    LogHelper.AddLog(db, LogType.FileProcessing, orderNumber,
                                     "LiveSeedFile processed: " + campaign.Assets.LiveSeedUrl + ", Status: " +
                                     System.Enum.GetName(typeof(UploadFileStatus), campaign.Assets.LiveSeedStatus));
                }

                // Suppression
                if (!string.IsNullOrEmpty(campaign.Assets.SuppressionFile))
                {
                    campaign.Assets.SuppressionUrl = FileManager.GetFilePathLive(UploadFileType.SuppressionFile,
                                                                                 campaign.OrderNumber);
                    campaign.Assets.SuppressionStatus = (int)UploadFileStatus.Completed;
                    LogHelper.AddLog(db, LogType.FileProcessing, orderNumber,
                                     "SuppressionFile processed: " + campaign.Assets.SuppressionUrl + ", Status: " +
                                     System.Enum.GetName(typeof(UploadFileStatus), campaign.Assets.SuppressionStatus));
                }
                db.SaveChanges();

                // Banner
                if (!string.IsNullOrEmpty(campaign.Assets.BannersFile))
                {
                    campaign.Assets.BannersUrl = FileManager.GetFilePathLive(UploadFileType.BannersFile,
                                                                             campaign.OrderNumber, Path.GetExtension(campaign.Assets.BannersFile));
                    campaign.Assets.BannersStatus = (int)UploadFileStatus.Completed;
                    LogHelper.AddLog(db, LogType.FileProcessing, orderNumber,
                                     "BannersFile processed: " + campaign.Assets.BannersUrl + ", Status: " +
                                     System.Enum.GetName(typeof(UploadFileStatus), campaign.Assets.BannersStatus));
                }

                // Banner Links
                if (!string.IsNullOrEmpty(campaign.Assets.BannerLinksFile))
                {
                    campaign.Assets.BannerLinksUrl = FileManager.GetFilePathLive(UploadFileType.BannersLinksFile,
                                                                                 campaign.OrderNumber, Path.GetExtension(campaign.Assets.BannerLinksFile));
                    campaign.Assets.BannerLinksStatus = (int)UploadFileStatus.Completed;
                    LogHelper.AddLog(db, LogType.FileProcessing, orderNumber,
                                     "BannerLinksFile processed: " + campaign.Assets.BannerLinksUrl + ", Status: " +
                                     System.Enum.GetName(typeof(UploadFileStatus), campaign.Assets.BannerLinksStatus));
                }

                // Misc
                if (!string.IsNullOrEmpty(campaign.Assets.MiscFile))
                {
                    campaign.Assets.MiscUrl = FileManager.GetFilePathLive(UploadFileType.MiscFile,
                                                                          campaign.OrderNumber, Path.GetExtension(campaign.Assets.MiscFile));
                    campaign.Assets.MiscStatus = (int)UploadFileStatus.Completed;
                    LogHelper.AddLog(db, LogType.FileProcessing, orderNumber,
                                     "MiscFile processed: " + campaign.Assets.MiscUrl + ", Status: " +
                                     System.Enum.GetName(typeof(UploadFileStatus), campaign.Assets.MiscStatus));
                }
            }
        }
예제 #11
0
        public ReportGenerationResultVm GenerateReport(Guid?id, Guid?trackingId, string template, string format)
        {
            Campaign campaign = Db.Campaigns
                                .Include(x => x.Assets)
                                .Include(x => x.Segments)
                                .Include(x => x.ProDatas)
                                .Include(x => x.Testing)
                                .Include(x => x.Approved)
                                .Include(x => x.Trackings)
                                .FirstOrDefault(x => x.Id == id);

            if (campaign == null)
            {
                throw new AdsException("Campaign not found.");
            }
            if (campaign.Approved == null)
            {
                throw new AdsException("Campaign is not passed through Testing and Approved phase.");
            }
            var campaignTracking = campaign.Trackings.FirstOrDefault(x => x.Id == trackingId);

            if (campaignTracking == null)
            {
                throw new AdsException("No Tracking data available.");
            }

            var whiteLable = Db.Customers.FirstOrDefault(x => x.WhiteLabel == campaign.Approved.WhiteLabel);

            if (whiteLable == null)
            {
                throw new AdsException("Campaign White Label not set in approved screen.");
            }

            var reportTemplate = !string.IsNullOrEmpty(template) ? template : whiteLable.ReportTemplate;

            // Creative HTML screenshot
            string creativeUrl            = campaign.Assets.CreativeUrl,
                   screenshotFilePathTemp = $"{UploadPath}\\{campaign.OrderNumber}t.png",
                   screenshotFilePath     = $"{UploadPath}\\{campaign.OrderNumber}.png";

            if (whiteLable.IsUseOpenModel && !string.IsNullOrEmpty(campaign.Assets.OpenModelImageFile))
            {
                S3FileManager.Download(campaign.Assets.OpenModelImageFile, screenshotFilePathTemp);
            }
            else
            {
                var helper = new ImageHelper(creativeUrl, screenshotFilePathTemp);
                if (!System.IO.File.Exists(screenshotFilePath))
                {
                    helper.Capture();
                }
            }
            int ScreenshotHeight = "Tracking1".Equals(reportTemplate) || "Tracking2".Equals(reportTemplate) || "TrackingReTargeting".Equals(reportTemplate) ? 750 : 500;

            if (System.IO.File.Exists(screenshotFilePathTemp))
            {
                ImageResizer.Resize(screenshotFilePathTemp, screenshotFilePath, 400, ScreenshotHeight, true);
                System.IO.File.Delete(screenshotFilePathTemp);
            }

            string contentType = "", outputFileName = "", outputFilePath = "";

            switch (format)
            {
            //case "pdf":
            //    var modelView = CampaignTrackingVm.FromCampaignTracking(campaign, campaignTracking);
            //    outputFileName = $"{campaign.OrderNumber} {whiteLable?.WhiteLabel}.pdf";
            //    outputFilePath = Path.Combine(DownloadPath, outputFileName);
            //    contentType = "application/pdf";
            //    // Generate pdf
            //    new TemplateReportPdf().Generate(modelView, outputFilePath, whiteLable.CompanyLogo, screenshotFilePath);
            //    break;
            // case "excel":
            default:
                var modelReport = TemplateReportVm.FromCampaignTracking(campaign, campaignTracking);
                outputFileName = $"{campaign.OrderNumber}.xlsx";
                outputFilePath = Path.Combine(DownloadPath, outputFileName);
                contentType    = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

                BaseTrackingReport report = null;
                switch (reportTemplate)
                {
                case "Tracking1":
                case "Tracking2":
                case "TrackingReTargeting":
                    report = new TrackingReportTemplate12(reportTemplate, campaign.Approved.WhiteLabel, whiteLable.CompanyLogo, screenshotFilePath);
                    break;

                case "Tracking3":
                case "Tracking4":
                    report = new TrackingReportTemplate34(reportTemplate, campaign.Approved.WhiteLabel, whiteLable.CompanyLogo, screenshotFilePath);
                    break;

                case "TrackingStrat":
                    report = new TrackingReportTemplateStrat(reportTemplate, campaign.Approved.WhiteLabel, whiteLable.CompanyLogo, screenshotFilePath);
                    break;

                default:
                    report = new TrackingReportTemplate12(reportTemplate, campaign.Approved.WhiteLabel, whiteLable.CompanyLogo, screenshotFilePath);
                    break;
                }
                report.Generate(modelReport, outputFilePath);

                break;
            }

            if ("pdf".Equals(format))
            {
                string outputFileNamePdf = $"{campaign.OrderNumber} {whiteLable?.WhiteLabel}t.pdf";
                string outputFilePathPdf = Path.Combine(DownloadPath, outputFileNamePdf);

                string outputFileNamePdfFinal = $"{campaign.OrderNumber} {whiteLable?.WhiteLabel}.pdf";
                string outputFilePathPdfFinal = Path.Combine(DownloadPath, outputFileNamePdfFinal);

                contentType = "application/pdf";

                Infrastructure.Pdf.Introp.Generate(outputFilePath, outputFilePathPdf);

                string pageSelection = ("Tracking1".Equals(reportTemplate) || "Tracking2".Equals(reportTemplate) ||
                                        "TrackingReTargeting".Equals(reportTemplate) || "Tracking3".Equals(reportTemplate) ? "1-2" :
                                        "Tracking4".Equals(reportTemplate) || "TrackingStrat".Equals(reportTemplate) ? "1-3" : "1");

                Infrastructure.Pdf.PdfOrganizer.SelectPages(outputFilePathPdf, pageSelection, outputFilePathPdfFinal);
                System.IO.File.Delete(outputFilePathPdf);

                outputFileName = outputFileNamePdfFinal;
                outputFilePath = outputFilePathPdfFinal;
            }

            return(new ReportGenerationResultVm()
            {
                orderNumber = campaign.OrderNumber,
                contentType = contentType,
                outputFileName = outputFileName,
                outputFilePath = outputFilePath
            });
        }
        public static void ProcessInput(WfpictContext db, string uploadPath, string dataFileUrl, string dynamicCodingFile, Guid?campaignId, string orderNumber)
        {
            List <DynamicCodingInput> inputs;

            try
            {
                inputs = LoadLookupInput(uploadPath, dynamicCodingFile);
            }
            catch (Exception ex)
            {
                throw new AdsException("There is something wrong with Dynamic Coding File. Please upload correct one." + ex.Message);
            }

            int TotalQuantityRequired = inputs.Sum(x => x.Qunatity);

            // Process Data file
            string dataFilePath = Path.Combine(uploadPath, dataFileUrl);

            S3FileManager.Download(dataFileUrl, dataFilePath);
            List <string> salesIds = GetRandomSalesIds(dataFilePath, TotalQuantityRequired);

            if (salesIds.Count < TotalQuantityRequired)
            {
                throw new AdsException("Sales Ids are less than required in the Dynamic links file. Please increase data file Quntity.");
            }

            // Add Lookups
            db.DynamicCodingLookups.RemoveRange(db.DynamicCodingLookups.Where(x => x.CampaignId == campaignId));
            db.SaveChanges();
            int Index = 1;

            foreach (var input in inputs)
            {
                db.DynamicCodingLookups.Add(new DynamicCodingLookup()
                {
                    Id          = Guid.NewGuid(),
                    CreatedAt   = DateTime.Now,
                    CampaignId  = campaignId,
                    OrderNumber = orderNumber,
                    OrignalURL  = input.OrignalURL,
                    URLType     = input.URLType,
                    Qunatity    = input.Qunatity,
                    VerumURL    = $"{orderNumber}/{input.URLType}/{Index}"
                });
                Index++;
            }
            db.SaveChanges();

            // Add Links
            db.DynamicCodingLinks.RemoveRange(db.DynamicCodingLinks.Where(x => x.CampaignId == campaignId));
            db.SaveChanges();
            int Index2 = 0;

            foreach (var lookUp in db.DynamicCodingLookups.Where(x => x.CampaignId == campaignId))
            {
                for (int quantity = 0; quantity < lookUp.Qunatity; quantity++)
                {
                    int salesId = Int32.Parse(salesIds[Index2]);
                    db.DynamicCodingLinks.Add(new DynamicCodingLink()
                    {
                        Id            = Guid.NewGuid(),
                        CreatedAt     = DateTime.Now,
                        CampaignId    = campaignId,
                        OrderNumber   = orderNumber,
                        SalesMasterId = salesId,
                        URLType       = lookUp.URLType,
                        OrignalURL    = lookUp.OrignalURL.Replace("{{unique}}", salesId.ToString()),
                        VerumURL      = lookUp.VerumURL,
                        IsURLRedemed  = false
                    });
                    Index2++;
                }
            }
            db.SaveChanges();
        }