using System.Web.Mvc; using UI.Infrastructure; using UI.Infrastructure.Impl; using UI.Models; namespace UI.Controllers { public class HomeController : Controller { private IEntryRepository _repository; public HomeController(IEntryRepository repository) { _repository = repository; } public HomeController() : this(new EntryRepository()){} [HttpGet] public ActionResult Index() { ViewModel.Message = "Please sign my guestbook."; return View(new Entry()); } [HttpPost] public ActionResult Index( EntryWithBusinessRules postedEntry) { if (ModelState.IsValid) { _repository.Save(postedEntry); return RedirectToAction("index"); } return View(postedEntry); } protected override void OnActionExecuted(ActionExecutedContext filterContext) { Entry[] allEntries = _repository.GetAll(); ViewModel.Entries = allEntries; } } }