public ActionResult Index(string reason = null) { var model = new ContactUsViewModel(); this.GetReasonFromQueryString(reason, model); return View(model); }
public ActionResult Index(ContactUsViewModel model) { List<string> emailAddresses = new List<string>(); string subject = string.Empty; if (ModelState.IsValid) { switch (model.Reason) { case ContactReason.AddPlayers: emailAddresses.Add(optionRepository.GetByName(Option.EXEC_EMAIL_REGISTRAR)); emailAddresses.Add(optionRepository.GetByName(Option.EXEC_EMAIL_WEBADMIN)); subject = this.GetSubject(model.Name, "needs to add some players"); break; case ContactReason.FoundBug: emailAddresses.Add(optionRepository.GetByName(Option.EXEC_EMAIL_WEBADMIN)); subject = this.GetSubject(model.Name, "has found a bug"); break; case ContactReason.NeedWebsiteHelp: emailAddresses.Add(optionRepository.GetByName(Option.EXEC_EMAIL_WEBADMIN)); subject = this.GetSubject(model.Name, "has a question"); break; case ContactReason.SomeOtherReason: emailAddresses.AddRange(GetExecEmailAddresses()); subject = this.GetSubject(model.Name, "has submitted some feedback"); break; } Email emailHandler = new Email(false); // Split and add email addresses foreach (string emailAddress in emailAddresses) emailHandler.AddToRecipient(emailAddress); try { emailHandler.Send(subject, model.Message, model.Email); return RedirectToAction("Sent"); } catch (EmailSendException) { TempData[FormMessages.MessageTypeFailure] = FormMessages.FeedbackSendError; } } return View(model); }
private void GetReasonFromQueryString(string reason, ContactUsViewModel model) { if (!string.IsNullOrEmpty(reason)) { ContactReason contactReason; if (Enum.TryParse(reason, true, out contactReason)) { model.Reason = contactReason; } } }