// TODO: Use ActionMailer to render emails, instead of this janky string formatting. public static PostmarkResponse SendChallengeRequestEmail(Challenge challenge, string challengeUrl) { string subject = "Timed challenge from " + challenge.SentBy; string body = string.Format( "{0} has sent you a timed challenge.\n" + "Visit {1} to start the challenge.\nEnter \"{2}\" (without the quotes) when prompted for your email address.", challenge.SentBy, challengeUrl, challenge.EmailAddress); return SendEmail(challenge.EmailAddress, challenge.SentBy, subject, body); }
public ActionResult Create(int templateId) { ViewBag.Title = "Create Challenge"; var challenge = new Challenge(); if (templateId > 0) { ChallengeTemplate template = Database.Open().ChallengeTemplates.FindById(templateId); challenge.Title = template.Title; challenge.Duration = template.Duration; challenge.Content = template.Content; } return View("ChallengeEditor", challenge); }
public ActionResult Create(FormCollection collection) { var challenge = new Challenge { SentBy = User.Identity.Name.Trim(), EmailAddress = collection["EmailAddress"].Trim(), Duration = Convert.ToInt32(collection["Duration"]), Title = collection["Title"].Trim(), Content = collection["Content"].TrimEnd() }; challenge = Database.Open().Challenges.Insert(challenge); string challengeUrl = Url.Action("Index", "Challenge", new {id = challenge.Id}, Request.Url.Scheme); PostmarkResponse response = EmailSender.SendChallengeRequestEmail(challenge, challengeUrl); if (response.Status != PostmarkStatus.Success) { ViewBag.ErrorMessage = response.Message; Database.Open().Challenges.DeleteById(challenge.Id); return View("ChallengeEditor", challenge); } return RedirectToAction("Index", "Home"); }