Files
LeafWeb/WebCms/Controllers/ContactController.cs
T

44 lines
1.2 KiB
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();
// if user is logged in, pre fill the name and email
var member = Members.GetCurrentMember();
if (member != null)
{
viewModel.Name = member.Name;
viewModel.Email= (string)member.GetProperty("Email").Value;
}
return PartialView(viewModel);
}
[HttpPost]
[ValidateRecaptcha]
public ActionResult Submit(ContactForm viewModel)
{
if (ModelState.IsValid)
{
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($"Thank you, {viewModel.Name}. Your message has been sent" , StatusType.Success);
return RedirectToCurrentUmbracoPage();
}
return CurrentUmbracoPage();
}
}
}