/// <summary> /// Create the sentItems (locked infomation on price and content about the campaign before confirmation and payment) /// </summary> /// <param name="campaign"></param> /// <returns></returns> public bool GenerateCampaignSentItems(Campaign campaign) { if (campaign.CampaignStateId != CampaignState.DefaultState) { return(false); } // Get all the profiles from the campaigns list var recipientProfiles = this.RecipientProfiles.Where(p => p.ProfileListId == campaign.ProfileListId); var template = this.LockedTemplates.Find(campaign.LockedTemplateId); // Remove all existing sentItems campaign.SentItems.Clear(); // foreach recipient loop over and create sentItems for each, using the template foreach (var profile in recipientProfiles) { SentItem sentItem = this.CreateSentItem(template, profile); campaign.SentItems.Add(sentItem); } campaign.CampaignStateId = CampaignState.PriceSet; // Update the price of the campaign campaign.SetCampaignPrice(); this.SetModified(campaign); this.SaveChanges(); return(true); }
private SentItem CreateSentItem(LockedTemplate template, RecipientProfile profile) { SentItem sentItem = new SentItem(); // Deep copy the relevant profile into a new profile sentItem.RecipientProfile = new RecipientProfile(profile); // Lock the profiles as a sent item so it cannot be modified sentItem.RecipientProfile.IsProfileLocked = true; // Parse the template with profile info TemplateParser parser = new TemplateParser(); sentItem.FrontHtml = parser.ParseTemplate(template.FrontHtml, profile); sentItem.BackHtml = parser.ParseTemplate(template.BackHtml, profile); sentItem.ItemTypeId = template.ItemTypeId; // Get the price of the mail item sentItem.LockedInPrice = this.Prices.Where(p => p.CountryId == profile.CountryId && p.ItemTypeId == template.ItemTypeId).FirstOrDefault().Ammount; return(sentItem); }