public ActionResult categorysubscriber(EmailSubscriptionViewModel model) { if (ModelState.IsValid) { string id = User.Identity.GetUserId(); var subQ = from s in db.EmailSubscriptions where s.Email.ToLower() == model.Email.ToLower() && s.CategoryId == model.GroupId select s; var sub = subQ.FirstOrDefault(); if (sub != null) { if (!String.IsNullOrEmpty(model.Choice) && model.Choice.ToLower() == "unsubscribe") { db.EmailSubscriptions.Remove(sub); db.SaveChanges(); ViewBag.Message = "Successfully updated your subsciption."; } else { sub.Period = model.Cycle; sub.Name = model.Name; if (!String.IsNullOrEmpty(id)) { sub.UserId = id; } sub.Updated = DateTime.Now; db.SaveChanges(); ViewBag.Message = "Successfully updated your subsciption."; } } else { sub = new EmailSubscriptions(); if (!String.IsNullOrEmpty(id)) { sub.UserId = id; } sub.Email = model.Email; sub.CategoryId = model.GroupId; sub.Name = model.Name; sub.Period = model.Cycle; sub.Started = DateTime.Now; db.EmailSubscriptions.Add(sub); db.SaveChanges(); ViewBag.Message = "Successfully updated your subsciption."; } } return(View(model)); }
private static int SendReminderEmails(HomeAppsLib.db.NFL_week weekAboutToExpire, EmailSubscriptionType emailSubscriptionType) { int count = 0; foreach (var user in EmailSubscriptions.GetSubscribedUsers(emailSubscriptionType)) { if (LibCommon.DBModel().NFL_userPicks.Count(x => x.week == weekAboutToExpire.week && x.username == user.name) == 0) { string to = LibCommon.IsDevelopmentEnvironment() ? "*****@*****.**" : user.email; int daysLeft = (weekAboutToExpire.exp_dt.Date - DateTime.Now.Date).Days; string subject = "Only " + daysLeft + " days left to make your picks!"; if (daysLeft == 1) { subject = subject.Replace("days", "day"); } if (daysLeft == 0) { subject = "Picks expire today!"; } //if (DateTime.Now < new DateTime(2016, 9, 10)) // subject = "FEATURING CORY QUICK PICKS!! " + subject; string body = "Hi, " + user.name + "!<br><br>"; body += "Remember, picks for <b>" + weekAboutToExpire.text + "</b> will expire on " + weekAboutToExpire.exp_dt.ToLongDateTimeDisplay() + "!<br><br>"; body += "<span style='font-size:x-large;'>Be sure to make your picks before then!</span><br>"; body += "<br><a href='" + LibCommon.WebsiteUrlRoot() + "nflpicks.aspx?quickpicks=true&autoweek=" + weekAboutToExpire.week + "&sso=" + LibCommon.SSOUserKey(user) + "' style='font-size:xx-large;'>CLICK HERE FOR NEW CORY QUICK PICKS!</span><br><br>"; body += "<span style='font-size:large;'><a href='" + LibCommon.WebsiteUrlRoot() + "'>Click here to log in and make your picks now</a></span><br><br>"; body += "Thanks,<br>The Wright Picks"; body += "<br><br><br><span style='font-size:small;'>P.S. If you'd like to unsubscribe from this email, click <a href='" + EmailSubscriptions.LinkToUnsubscripe(user, (int)emailSubscriptionType) + "'>here.</a></span>"; LibCommon.SendEmail(to, subject, body, "The Wright Picks", waitAfter: TimeSpan.FromSeconds(15)); if (user.name.ToLower() == "cory") { HomeAppsLib.LibCommon.SendCoryText(weekAboutToExpire.week); } count++; } } return(count); }
public async Task <ActionResult> RemoveAsync(Subscribe model) { if (!string.IsNullOrWhiteSpace(model.ConfirmEmailAddress)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (await EmailSubscriptions.RemoveAsync(this.Tenant, model.EmailAddress).ConfigureAwait(false)) { var email = new SubscriptionRemovedEmail(); await email.SendAsync(this.Tenant, model).ConfigureAwait(false); } await Task.Delay(1000).ConfigureAwait(false); return(this.Ok()); }
public async Task <ActionResult> RemoveAsync(Subscribe model) { if (!string.IsNullOrWhiteSpace(model.ConfirmEmailAddress)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } string tenant = AppUsers.GetTenant(); if (EmailSubscriptions.Remove(tenant, model.EmailAddress)) { var email = new SubscriptionRemovedEmail(); await email.SendAsync(tenant, model); } Thread.Sleep(1000); return(this.Ok()); }
public static int SendDailyForumRecaps() { int emailCount = 0; bool postsMade; string emailBody = GetEmailBody(out postsMade); if (postsMade) { foreach (HomeAppsLib.db.user user in EmailSubscriptions.GetSubscribedUsers(EmailSubscriptionType.DailyForumRecap)) { LibCommon.SendEmail(user.email, "Daily Disussion Recap", emailBody.Replace("XXXXXXXXXX", user.encPW), "The Wright Picks", waitAfter: TimeSpan.FromSeconds(1)); emailCount++; } } return(emailCount); }
public async Task <ActionResult> RemoveAsync(Subscribe model) { string token = this.Session[TokenKey].ToString(); if (token != model.TokenHidden || !string.IsNullOrWhiteSpace(model.ConfirmEmailAddress)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } string catalog = AppUsers.GetCatalog(); if (EmailSubscriptions.Remove(catalog, model.EmailAddress)) { var email = new SubscriptionRemovedEmail(); await email.SendAsync(catalog, model); } return(Json("OK")); }
private static string GetEmailBody(out bool postsMade) { DateTime start = DateTime.Now.AddDays(-1).Date; DateTime end = start.AddDays(1); string result = "<span style='font-size:x-large;'>Discussion Recap For " + start.ToLongDateDisplay() + ".</span><br><br>"; int numberOfPosts = 0; foreach (HomeAppsLib.db.NFL_forum post in LibCommon.DBModel().NFL_forums.Where(x => x.insert_dt >= start && x.insert_dt < end).OrderBy(x => x.insert_dt)) { numberOfPosts++; result += HomeAppsLib.EmailSubscriptions.GenerateDiscPostEmailBodyText(post); result += "<br><br>"; } if (numberOfPosts == 0) { result += "There are no discussions to report.<br><br>"; } postsMade = numberOfPosts > 0; result += "<a href='" + LibCommon.WebsiteUrlRoot() + "'>Click here to log in and view all discussions.</a><br><br>"; result += "Thanks,<br>The Wright Picks"; result += "<br><br><br><span style='font-size:small;'>P.S. If you'd like to unsubscribe from this email, click <a href='" + EmailSubscriptions.LinkToUnsubscripe("XXXXXXXXXX", (int)EmailSubscriptionType.DailyForumRecap) + "'>here.</a></span>"; return(result); }
public ActionResult subscribe(EmailSubscriptionListViewModel model) { string id = User.Identity.GetUserId(); ViewBag.cats = catHelper.subCategories(0); if (ModelState.IsValid) { //are they unsubscribing from all lists? if (model.subscriptionType == "unsubscribe") { var csubQ = from s in db.EmailSubscriptions where s.Email == model.Email select s; if (!String.IsNullOrEmpty(id)) { csubQ = csubQ.Where(s => s.UserId == id); } var csub = csubQ.ToList(); if (csub != null) { foreach (var sb in csub) { db.EmailSubscriptions.Remove(sb); } db.SaveChanges(); return(RedirectToAction("subscribe", new { s = "unsubscribe" })); } } else { foreach (var grp in model.Groups) { //check it's not a blank radio value/row if (!String.IsNullOrEmpty(grp.Cycle)) { string[] GroupCycle = grp.Cycle.Split(new char[] { '_' }); int groupId = Convert.ToInt32(GroupCycle[1]); string cycle = GroupCycle[0]; var subQ = from s in db.EmailSubscriptions where s.Email.ToLower() == model.Email.ToLower() && s.CategoryId == groupId select s; var emlSub = subQ.FirstOrDefault(); if (emlSub == null) { emlSub = new EmailSubscriptions(); emlSub.Email = model.Email; emlSub.CategoryId = groupId; emlSub.Name = model.Name; emlSub.Period = cycle; if (!String.IsNullOrEmpty(id)) { emlSub.UserId = id; } emlSub.Started = DateTime.Now; db.EmailSubscriptions.Add(emlSub); db.SaveChanges(); } else { if (!String.IsNullOrEmpty(id)) { emlSub.UserId = id; } if (model.subscriptionType == "subscribe") { emlSub.Name = model.Name; emlSub.Period = cycle; emlSub.Updated = DateTime.Now; db.SaveChanges(); } } ViewBag.Message = "Your subscription has been updated successfully."; } } } } return(View(model)); }