Files
LeafWeb/WebCms/Controllers/ContactController.cs
T
2020-01-26 09:05:54 -05:00

35 lines
938 B
C#

using System.Web.Mvc;
using Hangfire;
using log4net;
using LeafWeb.WebCms.Models;
using LeafWeb.WebCms.Services;
namespace LeafWeb.WebCms.Controllers
{
public class ContactController : BaseController
{
public ActionResult Index()
{
var viewModel = new ContactForm();
return PartialView(viewModel);
}
[HttpPost]
public ActionResult Submit(ContactForm viewModel)
{
if (ModelState.IsValid) // HttpParamMatch indicates it's backing out from Confirm
{
BackgroundJob.Enqueue<EmailNotificationService>(
e => e.SendContactEmail(viewModel));
var logger = LogManager.GetLogger(GetType());
logger.Info($"Contact: Name:{viewModel.Name} Added, Email:{viewModel.Email}, Message:{viewModel.Message}");
SetStatusMessage("Your message has been sent!", StatusType.Success);
return RedirectToCurrentUmbracoPage();
}
return CurrentUmbracoPage();
}
}
}