/// <summary> /// Mails information about a smile to all subscribers, based on both point and organization subscriptions. /// </summary> /// <param name="smile">Smile to mail for.</param> public void mailSmileToSubscribers(Smile smile) { SendASmile.Mailers.ISmileMailer mail = new SendASmile.Mailers.SmileMailer(); using (var db = new SmileContext()) { List<MailSub> listOrgs = db.MailSub.Include(p => p.point).Include(o => o.org).Where(o => o.org.orgID == smile.point.organization.orgID).ToList(); List<MailSub> listPoints = db.MailSub.Include(p => p.point).Include(o => o.org).Where(p => p.point.pointID == smile.point.pointID).ToList(); foreach (var x in listOrgs) { if (smile.isSmile) { mail.smileLogged(smile, x.email, x.subId).SendAsync(); } else { mail.frownLogged(smile, x.email, x.subId).SendAsync(); } } foreach (var x in listPoints) { if (smile.isSmile) { mail.smileLogged(smile, x.email, x.subId).SendAsync(); } else { mail.frownLogged(smile, x.email, x.subId).SendAsync(); } } } }
public ActionResult Unsub(int subId, string email) { using (var db = new SmileContext()) { if (db.MailSub.Where(s => s.subId == subId).Where(e => e.email == email).Count() > 0) { var sub = db.MailSub.Find(subId); db.MailSub.Remove(sub); db.SaveChanges(); Response.RedirectToRoute(new { controller = "MailSub", action = "Success" }); } else { Response.RedirectToRoute(new {controller = "MailSub", action = "Failure" }); } } return View(subId); }