Skip to content

Commit

Permalink
Phase 4: Site config that is not likely to change much
Browse files Browse the repository at this point in the history
  • Loading branch information
synhershko committed Dec 4, 2011
1 parent 0e6266c commit 98de609
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 7 deletions.
3 changes: 1 addition & 2 deletions EventsZilla/Controllers/EventController.cs
Expand Up @@ -2,11 +2,10 @@
using System.Linq;
using System.Web.Mvc;
using EventsZilla.Models;
using HibernatingRhinos.Loci.Common.Controllers;

namespace EventsZilla.Controllers
{
public class EventController : RavenController
public class EventController : ZillaController
{
public ActionResult Index(int id, string slug)
{
Expand Down
3 changes: 1 addition & 2 deletions EventsZilla/Controllers/HomeController.cs
Expand Up @@ -2,11 +2,10 @@
using System.Web.Mvc;
using System.Linq;
using EventsZilla.Models;
using HibernatingRhinos.Loci.Common.Controllers;

namespace EventsZilla.Controllers
{
public class HomeController : RavenController
public class HomeController : ZillaController
{
public ActionResult Index()
{
Expand Down
20 changes: 20 additions & 0 deletions EventsZilla/Controllers/ZillaController.cs
@@ -0,0 +1,20 @@
using System;
using System.Web.Mvc;
using EventsZilla.Models;
using HibernatingRhinos.Loci.Common.Controllers;

namespace EventsZilla.Controllers
{
public class ZillaController : RavenController
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);

using (RavenSession.Advanced.DocumentStore.AggressivelyCacheFor(TimeSpan.FromMinutes(30)))
{
ViewBag.SiteConfig = RavenSession.Load<SiteConfig>(SiteConfig.ConfigName);
}
}
}
}
2 changes: 2 additions & 0 deletions EventsZilla/EventsZilla.csproj
Expand Up @@ -100,6 +100,7 @@
<Compile Include="Areas\Admin\Controllers\EventsController.cs" />
<Compile Include="Controllers\EventController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\ZillaController.cs" />
<Compile Include="Core\ContentHelpers.cs" />
<Compile Include="Core\RavenHelpers.cs" />
<Compile Include="Core\RavenIndexDefinitions.cs" />
Expand All @@ -114,6 +115,7 @@
<Compile Include="Models\EventRegistration.cs" />
<Compile Include="Models\Feedback.cs" />
<Compile Include="Models\Presenter.cs" />
<Compile Include="Models\SiteConfig.cs" />
<Compile Include="Models\Venue.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
12 changes: 10 additions & 2 deletions EventsZilla/Global.asax.cs
Expand Up @@ -4,6 +4,7 @@
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using EventsZilla.Models;
using HibernatingRhinos.Loci.Common.Controllers;
using HibernatingRhinos.Loci.Common.Routing;
using HibernatingRhinos.Loci.Common.Tasks;
Expand Down Expand Up @@ -60,8 +61,6 @@ protected void Application_Start()

InitializeRaven();



RavenController.DocumentStore = _store;
TaskExecutor.DocumentStore = _store;

Expand Down Expand Up @@ -94,6 +93,15 @@ private static void InitializeRaven()

IndexCreation.CreateIndexes(Assembly.GetCallingAssembly(), _store);

using (var session = _store.OpenSession())
{
if (session.Load<SiteConfig>(SiteConfig.ConfigName) == null)
{
session.Store(new SiteConfig { RequireRegistration = true }, SiteConfig.ConfigName);
session.SaveChanges();
}
}

ConfigureVersioning();
}
catch (Exception e)
Expand Down
10 changes: 10 additions & 0 deletions EventsZilla/Models/SiteConfig.cs
@@ -0,0 +1,10 @@
namespace EventsZilla.Models
{
public class SiteConfig
{
public string WebsiteHeader { get; set; }
public bool RequireRegistration { get; set; }

public static string ConfigName { get { return "Configs/Site"; } }
}
}
8 changes: 7 additions & 1 deletion EventsZilla/Views/Shared/_Layout.cshtml
@@ -1,4 +1,8 @@
@using EventsZilla.Core
@using EventsZilla.Models
@{
var siteConfig = ViewBag.SiteConfig as SiteConfig ?? new SiteConfig();
}
<!doctype html>
<head>
<meta charset="UTF-8">
Expand Down Expand Up @@ -49,7 +53,9 @@
<!--end header-->
</header>

@RenderBody()
@MvcHtmlString.Create(siteConfig.WebsiteHeader)

@RenderBody()

</div>
<!--end container-->
Expand Down

0 comments on commit 98de609

Please sign in to comment.