-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPostGetController.cs
More file actions
63 lines (54 loc) · 1.6 KB
/
PostGetController.cs
File metadata and controls
63 lines (54 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using Blog.Web.Core;
using Blog.Web.Infrastructure;
namespace Blog.Web.Actions.PostGet
{
public class PostGetModule : IModule
{
public void Execute(IContainer container)
{
var root = HttpContext.Current.Server.MapPath("~/Content/posts");
container.Register(c => new PostGetController(c.Resolve<IMediator>()));
var mediator = container.Resolve<ISubscribeHandlers>();
mediator.Subscribe<PostRequest, PostGetViewModel>(message =>
{
var result = new PostGetViewModel();
result = new FilteredPostVault().Handle(message, result);
result = new MarkdownContentStorage(root).Handle(message, result);
return result;
});
}
}
public class PostGetController : Controller
{
private readonly IMediator _mediator;
public PostGetController(IMediator mediator)
{
_mediator = mediator;
}
public ActionResult Execute(PostRequest request)
{
var model = _mediator.Send<PostRequest, PostGetViewModel>(request);
if (model.Post == null) return HttpNotFound();
return View(model);
}
}
public class PostRequest
{
public string Slug { get; set; }
}
public class PostGetViewModel
{
public Post Post { get; set; }
public string Content { get; set; }
public Post Previous { get; set; }
public Post Next { get; set; }
public IReadOnlyCollection<Post> Active { get; set; }
public IReadOnlyCollection<Post> Future { get; set; }
public bool HasPrevious { get { return Previous != null; } }
public bool HasNext { get { return Next != null; } }
}
}