public ActionResult NewSegment(string orderNumber) { Campaign campaign = Db.Campaigns .Include(x => x.Assets).Include(x => x.Testing) .FirstOrDefault(x => x.OrderNumber == orderNumber); var segment = new CampaignSegment() { Id = Guid.NewGuid(), CreatedAt = DateTime.Now, SegmentNumber = orderNumber + _c1, }; if (_c1 == 'A') { segment.SubjectLine = campaign.Testing.SubjectLine; segment.FromLine = campaign.Testing.FromLine; segment.WhiteLabel = campaign.Testing.WhiteLabel; segment.Quantity = campaign.Testing.Quantity; segment.DeploymentDate = campaign.Testing.DeployDate; segment.CreativeFiles = campaign.Assets.CreativeFiles; } _c1++; ViewBag.WhiteLabel = new SelectList(CustomersWithWLList, "Value", "Text", campaign.Testing.WhiteLabel); return(PartialView("~/Views/Shared/Editors/_NewSegment.cshtml", segment)); }
/// <summary> /// Limited to campaigns containing emails and segments /// </summary> public Campaign CreateCampaign(int emailId, int segmentId) { CampaignEmail campaignEmail = _elementHelper.GetCampaignEmail(emailId, -101); CampaignSegment campaignSegment = _elementHelper.GetCampaignSegment(segmentId, -100, -101); Campaign campaign = new Campaign { name = "sample campaign", campaignType = "sample", type = "Campaign", startAt = ConvertToUnixEpoch(DateTime.Now), endAt = ConvertToUnixEpoch(DateTime.Today.AddDays(1)), elements = new List <CampaignElement> { campaignSegment, campaignEmail } }; RestRequest request = new RestRequest(Method.POST) { Resource = "/assets/campaign", RequestFormat = DataFormat.Json }; request.AddBody(campaign); IRestResponse <Campaign> response = _client.Execute <Campaign>(request); return(response.Data); }
public static ProDataResponse Create(Campaign campaign, CampaignSegment segment, string whiteLabelDomain) { string orderNumber = segment != null ? $"ADS{segment.SegmentNumber}" : (campaign.ReBroadcasted ? $"ADS{campaign.ReBroadcastedOrderNumber}" : $"ADS{campaign.OrderNumber}"); double ctrPercent = campaign.Approved.OpenGoals == 0 ? 0 : (double)campaign.Approved.ClickGoals / campaign.Approved.OpenGoals; if (ctrPercent > 1.0) { ctrPercent = ctrPercent / 100.0; } ProDataRequest request = new ProDataRequest() { io = orderNumber, campaign_name = campaign.Approved.CampaignName, is_rebroadcast = campaign.Approved.ReBroadCast ? "Y" : "N", white_label = whiteLabelDomain, creative_url = campaign.Assets.CreativeUrl, quantity = campaign.Approved.Quantity, geo_type = "POSTALCODE", geo_url = campaign.Assets.ZipCodeUrl, open_percent = (double)campaign.Approved.OpenGoals / campaign.Approved.Quantity, ctr_percent = ctrPercent, subject = campaign.Approved.SubjectLine, from_name = campaign.Approved.FromLine, from_email = campaign.RepresentativeEmail, deploy_date = campaign.Approved.DeployDate?.ToString(StringConstants.DateTimeFormatDashes), }; if (campaign.Approved.IsOpenPixel) { request.is_open_pixel = "Y"; request.open_pixel = campaign.Approved.OpenPixelUrl; } else { request.is_open_pixel = "N"; } if (!string.IsNullOrEmpty(segment?.SegmentDataFileUrl)) { request.is_data_file = "Y"; request.data_file_url = segment.SegmentDataFileUrl; request.data_file_replacement_param = segment.SegmentNumber; request.data_file_replacement_column = "0"; request.data_file_unique_ip = "Y"; } else { request.is_data_file = "N"; } return(Create(request)); }
public ActionResult NewSegment() { var segment = new CampaignSegment() { Id = Guid.NewGuid(), CreatedAt = DateTime.Now, SegmentNumber = "" + _c1++, //WhiteLabel = LoggedInUser?.Customer?.WhiteLabel }; ViewBag.WhiteLabel = new SelectList(CustomersWithWLList, "Value", "Text", LoggedInUser?.Customer?.WhiteLabel); return(PartialView("~/Views/Shared/Editors/_NewSegment.cshtml", segment)); }
public ActionResult CloneConfirmed(Guid id) { var camps = Db.Campaigns.ToList(); int newOrderNumber = camps.Count > 0 ? camps.Max(x => int.Parse(x.OrderNumber.TrimEnd("RDP".ToCharArray()))) + 1 : 2500; Campaign campaign = Db.Campaigns .Include(x => x.Assets) .Include(x => x.Segments) .Include(x => x.Testing) .Include(x => x.Approved) .FirstOrDefault(x => x.Id == id); var copyId = Guid.NewGuid(); var copy = new Campaign(); Db.Campaigns.Add(copy); Db.Entry(copy).CurrentValues.SetValues(Db.Entry(campaign).CurrentValues); copy.Id = copyId; copy.CreatedAt = DateTime.Now; copy.OrderNumber = newOrderNumber.ToString(); copy.Status = (int)CampaignStatus.OrderRecevied; copy.TestingId = null; copy.ApprovedId = null; Db.SaveChanges(); var copyAssets = new CampaignAsset(); Db.CampaignAssets.Add(copyAssets); Db.Entry(copyAssets).CurrentValues.SetValues(Db.Entry(campaign.Assets).CurrentValues); copyAssets.Id = Guid.NewGuid(); copyAssets.CampaignId = copyId; copyAssets.CreatedAt = DateTime.Now; Db.SaveChanges(); copy.AssetsId = copyAssets.Id; Db.SaveChanges(); foreach (var segment in campaign.Segments.ToList()) { var copySegment = new CampaignSegment(); Db.CampaignSegments.Add(copySegment); Db.Entry(copySegment).CurrentValues.SetValues(Db.Entry(segment).CurrentValues); copySegment.Id = Guid.NewGuid(); copySegment.CampaignId = copyId; copySegment.OrderNumber = "" + newOrderNumber; copySegment.CreatedAt = DateTime.Now; Db.SaveChanges(); } if (campaign.Testing != null) { //var testingId = Guid.NewGuid(); //var testing = new CampaignTesting(); //Db.CampaignsTesting.Add(testing); //Db.Entry(testing).CurrentValues.SetValues(Db.Entry(campaign.Testing).CurrentValues); //testing.Id = testingId; //testing.CreatedAt = DateTime.Now; //testing.CampaignId = copy.Id; //Db.SaveChanges(); //copy.TestingId = testingId; //Db.SaveChanges(); // don't add new testing, update some values from testing copy.CampaignName = campaign.Testing.CampaignName; copy.WhiteLabel = campaign.Testing.WhiteLabel; copy.FromLine = campaign.Testing.FromLine; copy.SubjectLine = campaign.Testing.SubjectLine; copy.BroadcastDate = campaign.Testing.DeployDate; copy.Quantity = campaign.Testing.Quantity; copy.ReBroadcastDate = campaign.Testing.ReBroadcastDate; copy.GeoDetails = campaign.Testing.GeoDetails; copy.Demographics = campaign.Testing.Demographics; copy.SpecialInstructions = campaign.Testing.SpecialInstructions; copy.IsOpenPixel = campaign.Testing.IsOpenPixel; copy.OpenPixelUrl = campaign.Testing.OpenPixelUrl; Db.SaveChanges(); } if (campaign.Approved != null) { //var approvedId = Guid.NewGuid(); //var approved = new CampaignApproved(); //Db.CampaignsApproved.Add(approved); //Db.Entry(approved).CurrentValues.SetValues(Db.Entry(campaign.Approved).CurrentValues); //approved.Id = approvedId; //approved.CreatedAt = DateTime.Now; //approved.CampaignId = copy.Id; //Db.SaveChanges(); //copy.ApprovedId = approvedId; //Db.SaveChanges(); // don't add new approved, update copy some values from approved copy.CampaignName = campaign.Approved.CampaignName; copy.WhiteLabel = campaign.Approved.WhiteLabel; copy.FromLine = campaign.Approved.FromLine; copy.SubjectLine = campaign.Approved.SubjectLine; copy.BroadcastDate = campaign.Approved.DeployDate; copy.Quantity = campaign.Approved.Quantity; copy.ReBroadcastDate = campaign.Approved.ReBroadcastDate; copy.GeoDetails = campaign.Approved.GeoDetails; copy.Demographics = campaign.Approved.Demographics; copy.SpecialInstructions = campaign.Approved.SpecialInstructions; copy.IsOpenPixel = campaign.Approved.IsOpenPixel; copy.OpenPixelUrl = campaign.Approved.OpenPixelUrl; Db.SaveChanges(); } ForceOrders = true; TempData["Success"] = "Order : " + campaign.OrderNumber + " has been cloned to Order: " + newOrderNumber + " sucessfully."; return(RedirectToAction("Index", "Campaigns")); }
private static void WriteAndUploadSegmentDataFile(List <SegmentResponse> data, WfpictContext db, CampaignSegment segment, string uploadPath, string orderNumber, Guid campaignId) { string fileName1 = $"{orderNumber}\\{segment.SegmentNumber}data.csv"; var filePath1 = $"{uploadPath}\\{fileName1}"; var data1 = data.Where(x => x.Index >= segment.FirstRangeStart && x.Index <= segment.FirstRangeEnd).ToList(); var data2 = data.Where(x => x.Index >= segment.SecondRangeStart && x.Index <= segment.SecondRangeEnd) .ToList(); var data3 = data.Where(x => x.Index >= segment.ThirdRangeStart && x.Index <= segment.ThirdRangeEnd).ToList(); data2.AddRange(data3); data1.AddRange(data2); data1 = data1.OrderBy(x => x.Index).ToList(); data1.ToCsv(filePath1, new CsvDefinition() { EndOfLine = "\r\n", FieldSeparator = ',', TextQualifier = '"', Columns = new List <string> { "SalesMasterId", "FirstName", "LastName", "Address", "City", "State", "Zip", "Zip4", "Apt", "Dealership_ID", "Index", } }); string amazonFileKey1 = $"{orderNumber}/{segment.SegmentNumber}data.csv"; S3FileManager.Upload(amazonFileKey1, filePath1, true); segment.SegmentDataFileUrl = FileManager.GetFilePathLive(UploadFileType.DataFile, orderNumber, string.Empty, segment.SegmentNumber); segment.DateFetched = DateTime.Now; segment.UploadStatus = (int)UploadFileStatus.Completed; segment.SegmentStatus = (int)SegmentStatus.Generated; LogHelper.AddLog(db, LogType.DataProcessing, orderNumber, fileName1 + " data file generated and uploaded to Amazon sucessfully."); }
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)); }
public static string SendApprovedToVendor(Vendor vendor, Campaign campaign, CampaignSegment segment) { string newOld = campaign.ReBroadcasted ? "RDP" : "New"; string deployDate = campaign.ReBroadcasted ? campaign.ReBroadcastedDate?.ToString("d") : campaign.Approved.DeployDate?.ToString("d"); string deployTime = campaign.ReBroadcasted ? campaign.ReBroadcastedDate?.ToString("hh:mm") : campaign.Approved.DeployDate?.ToString("hh:mm"); string quantity = campaign.ReBroadcasted ? campaign.ReBroadcastedQuantity.ToString() : campaign.Approved.Quantity.ToString(); string orderNumber; string subject; string segmentsHtml = string.Empty; if (segment == null) { // {clientCode} ADS / NSX orderNumber = campaign.ReBroadcasted ? $"{clientCode}{campaign.ReBroadcastedOrderNumber}" : $"{clientCode}{campaign.OrderNumber}"; subject = $"{newOld} Order {campaign.Approved.CampaignName}, Order # {orderNumber}"; } else { orderNumber = $"{clientCode}{segment.SegmentNumber}"; subject = $"{newOld} Order {campaign.Approved.CampaignName}, Order # {orderNumber}"; // <tr><th align=""left"">Data File</th><td>{segment.SegmentDataFileUrl}</td></tr> segmentsHtml += $@"<table border=""1""> <tr><th align=""left"">Segment</th><td>{segment.SegmentNumber}</td></tr> <tr><th align=""left"">Subject Line</th><td>{segment.SubjectLine}</td></tr> <tr><th align=""left"">From Line</th><td>{segment.FromLine}</td></tr> <tr><th align=""left"">White Label</th><td>{segment.WhiteLabel}</td></tr> <tr><th align=""left"">Deployment Date</th><td>{segment.DeploymentDate}</td></tr> <tr><th align=""left"">Total Records</th><td>{NumberHelper.GetTotal( segment.FirstRangeStart, segment.FirstRangeEnd, segment.SecondRangeStart, segment.SecondRangeEnd, segment.ThirdRangeStart, segment.ThirdRangeEnd)}</td></tr></table>"; } string body = $@"<br/><p>Dear {vendor.Name}</p><br/> Please find below Order details<br/><br/> <table border=""2""> <tr><th align=""left""> Reference #:</th><td>{campaign.Approved.ReferenceNumber}</td></tr> <tr><th align=""left"">Order #:</th><td>{orderNumber}</td></tr> <tr><th align=""left"">Campaign Name:</th><td>{campaign.Approved.CampaignName}</td></tr> <tr><th align=""left"">Rebroadcast:</th><td>{(campaign.Approved.ReBroadCast? "Yes": "No")}</td></tr> <tr><th align=""left"">Broadcast Date:</th><td>{campaign.Approved.DeployDate.Value:d}</td></tr> <tr><th align=""left"">From Line:</th><td>{campaign.Approved.FromLine}</td></tr> <tr><th align=""left"">Subject Line:</th><td>{campaign.Approved.SubjectLine}</td></tr> <tr><th align=""left"">Opt Out:</th><td>{campaign.OptOut}</td></tr> <tr><th align=""left"">White Label:</th><td>{campaign.Approved.WhiteLabel}</td></tr> <tr><th align=""left"">Personalization:</th><td>{(campaign.IsPersonalization? "Yes": "No")}</td></tr> <tr><th align=""left"">Creative URL:</th><td>{campaign.Assets.CreativeUrl}</td></tr> <tr><th align=""left"">Quantity:</th><td>{quantity}</td></tr> <tr><th align=""left"">Geo (s):</th><td>{campaign.Approved.GeoDetails}</td></tr> <tr><th align=""left"">Demographics:</th><td>{campaign.Approved.Demographics}</td></tr> <tr><tr><th align=""left"">Zip URL:</th><td>{campaign.Assets.ZipCodeUrl}</td></tr> <tr><th align=""left"">Special Instructions:</th><td>{campaign.Approved.SpecialInstructions}</td></tr> <tr><th align=""left"">Deploy Date:</th><td>{deployDate}</td></tr> <tr><th align=""left"">Deploy Time:</th><td>{deployTime}</td></tr> <tr><th align=""left"">Data Breakout:</th><td>{campaign.Testing.DataFileUrl}</td></tr> <tr><th align=""left"">Has Open Pixel:</th><td>{(campaign.Approved.IsOpenPixel? "Yes": "No")}</td></tr> <tr><th align=""left"">Open Pixel URL:</th><td>{campaign.Approved.OpenPixelUrl}</td></tr> <tr><th align=""left"">Omni Channel:</th><td>{(campaign.Approved.IsOmniOrder? "Y" : "N")}</td></tr> <tr><th align=""left"">Banner URL:</th><td>{campaign.Approved.BannerUrl}</td></tr> <tr><th align=""left"">Open Goals:</th><td>{campaign.Approved.OpenGoals}</td></tr> <tr><th align=""left"">Click Goals:</th><td>{campaign.Approved.ClickGoals}</td></tr> <tr><th align=""left"">Segment Data:</th><td>{segmentsHtml}</td></tr> </table></p> <p></p> {Footer}"; // <tr><th align=""left"">ReportSite Link:</th><td>{campaign.Approved.ReportSiteLink}</td></tr> SendEmail(vendor.Email, subject, body, vendor.CcEmails); return(body); }