using System; using System.Web.Mvc; using System.Web.UI; using AutoMapper; using DR.FV2016.Service.Interfaces; using DR.FV2016.Web.Helpers; using DR.FV2016.Web.Models; using DR.FV2016.Web.Models.Constituency; namespace DR.FV2016.Web.Controllers { public class ConstituencyController : Controller { private readonly IConstituencyService _constituencyService; private readonly IArticleService _articleService; public ConstituencyController(IConstituencyService constituencyService, IArticleService articleService) { if (constituencyService == null) throw new ArgumentNullException("constituencyService", "constituencyService may not be null."); if(articleService == null) throw new ArgumentNullException("articleService", "An instance of IArticleService is required."); _constituencyService = constituencyService; _articleService = articleService; } [OutputCache(Location = OutputCacheLocation.Downstream, Duration = 180)] public ActionResult Index() { var wrapper = _articleService.GetDefaultArticleWrapper(); var model = Mapper.Map(wrapper); model.GreaterConstituencies = ConstituencyHelper.AllConstituencies(Mapper.Engine, _constituencyService); model.IsResponsive = true; SearchableHelper.EnsureUrn(model, "urn:dr:valg2015:se-din-stemmeseddel"); return View(model); } [OutputCache(Location = OutputCacheLocation.Downstream, Duration = 180)] public ActionResult ConstituencyInfo(int constituencyId) { if(constituencyId <= 0) throw new ArgumentOutOfRangeException("constituencyId"); var constituency = Mapper.Map(_constituencyService.GetConstituency(constituencyId)); return Json(constituency, JsonRequestBehavior.AllowGet); } [OutputCache(Location = OutputCacheLocation.Downstream, Duration = 180)] public ActionResult MobileLandingPage() { var wrapper = _articleService.GetDefaultArticleWrapper(); var model = Mapper.Map(wrapper); model.GreaterConstituencies = ConstituencyHelper.AllConstituencies(Mapper.Engine, _constituencyService); model.IsResponsive = true; return View(model); } } }