public ActionResult DeleteConfirmed(int id) { CampaignLead campaignLead = db.CampaignLeads.Find(id); db.CampaignLeads.Remove(campaignLead); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ID,FirstName,LastName,Email,Phone")] CampaignLead campaignLead) { if (ModelState.IsValid) { db.Entry(campaignLead).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(campaignLead)); }
public ActionResult Create([Bind(Include = "ID,FirstName,LastName,Email,Phone")] CampaignLead campaignLead) { if (ModelState.IsValid) { db.CampaignLeads.Add(campaignLead); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(campaignLead)); }
// GET: CampaignLeads/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CampaignLead campaignLead = db.CampaignLeads.Find(id); if (campaignLead == null) { return(HttpNotFound()); } return(View(campaignLead)); }
public IHttpActionResult ActiveCampaignLeads(string customerNo) { List <CampaignLead> leadList = new List <CampaignLead>(); using (var context = new LMSEntities()) { context.Configuration.LazyLoadingEnabled = false; var query = from a in context.CampaignLeads join b in context.Campaigns on a.CampaignID equals b.CampaignID where a.Closed == 0 && a.CustomerNo == customerNo select new { CampaignLead = a, Campaign = b }; foreach (var item in query) { CampaignLead campaignLead = item.CampaignLead; campaignLead.CampaignName = item.Campaign.CampaignName; leadList.Add(campaignLead); } } return(Json(leadList)); }
/// <summary> /// Signs up. /// </summary> /// <param name="email">The email.</param> /// <param name="name">The name.</param> /// <param name="surname">The surname.</param> /// <param name="campaignId">The campaign identifier.</param> /// <param name="referralId">The referral identifier.</param> /// <param name="source">The source.</param> /// <param name="medium">The medium.</param> /// <returns>CampaignLead.</returns> /// <exception cref="Exception"> /// You have already signed up for this competition /// or /// Could not find matching campaign /// </exception> public CampaignLead SignUp(string email, string name, string surname, int campaignId, int?referralId, string source = null, string medium = null) { email = email.Trim().ToUpperInvariant(); var existingLead = _context.CampaignLeads.FirstOrDefault(a => a.Email == email && a.CampaignId == campaignId); if (existingLead != null) { throw new Exception("You have already signed up for this competition"); } var lookupKey = campaignId + Configs.CampaignSettingsKey; var existingCampaign = _cache.Get <Campaign>(lookupKey); if (existingCampaign == null) { existingCampaign = _context.Campaigns .Include(a => a.CampaignSettings) .Include(a => a.Organisation) .ThenInclude(a => a.OrganisationMandrillSettings) .Include(a => a.Organisation) .ThenInclude(a => a.OrganisationGeneralSettings) .FirstOrDefault(a => a.Id == campaignId); if (existingCampaign == null) { throw new Exception("Could not find matching campaign"); } _cache.Set(lookupKey, existingCampaign, TimeSpan.FromMinutes(5)); } var newLead = new CampaignLead { CampaignId = campaignId, Name = name, Surname = surname, Email = email, ReferralId = referralId, UtmSource = source, UtmCampaign = existingCampaign.Slug, UtmMedium = medium }; _context.CampaignLeads.Add(newLead); _context.SaveChanges(); if (referralId != null) { var referralLead = _context.CampaignLeads.Include(a => a.EmailReferrals) .FirstOrDefault(a => a.Id == referralId); if (referralLead != null) { var emailReferral = referralLead.EmailReferrals.FirstOrDefault(a => a.Email == email); if (emailReferral != null) { emailReferral.Status = "Success"; } else { referralLead.EmailReferrals.Add(new CampaignEmailReferral { Status = "Success", Email = email, Name = name, Surname = surname }); } _context.CampaignLeads.Update(referralLead); _context.SaveChanges(); } } var campaignSettings = existingCampaign.CampaignSettings; var organisationMandrillSettings = existingCampaign.Organisation.OrganisationMandrillSettings; var data = new Dictionary <string, object> { { "LeadName", name }, { "LeadSurname", surname }, { "WebsiteUrl", string.Format("{0}/e/{1}", existingCampaign.Organisation.OrganisationGeneralSettings.WebsiteBaseUrl, existingCampaign.Slug) } }; BackgroundJob.Enqueue <EmailSender>(a => a.SendEmail(email, campaignSettings.MandrillLeadTemplate, campaignSettings.LeadSubjectLine, data, organisationMandrillSettings.FromEmail, organisationMandrillSettings.ApiKey)); return(newLead); }