add method to generate a pdf file of the race session.

this may move to api, not sure.
This commit is contained in:
chris.watts90@outlook.com 2017-06-26 21:27:44 +01:00
parent 43f6899ddb
commit 610a69a18e

View File

@ -1,5 +1,8 @@
using System; using System;
using System.Dynamic;
using System.IO;
using Nancy; using Nancy;
using Nancy.ViewEngines;
namespace RaceLapTimer.Modules namespace RaceLapTimer.Modules
{ {
@ -8,10 +11,36 @@ namespace RaceLapTimer.Modules
public HistoryModule():base("/history") public HistoryModule():base("/history")
{ {
Get[""] = args => GetHistoryHomePage(); Get[""] = args => GetHistoryHomePage();
Get["/pdf/{id}"] = args => GetPdfFile(args);
}
private dynamic GetPdfFile(dynamic args)
{
var raceSessionId = (int)args.Id;
ViewLocationContext viewLocationContext = new ViewLocationContext()
{
Context = Context,
ModuleName = base.GetType().Name,
ModulePath = ModulePath
};
var rendered = ViewFactory.RenderView("HistoryIndex.cshtml", null, viewLocationContext);
var content = "";
using (var ms = new MemoryStream())
{
rendered.Contents.Invoke(ms);
ms.Seek(0, SeekOrigin.Begin);
using (TextReader reader = new StreamReader(ms))
{
content = reader.ReadToEnd();
}
};
throw new NotImplementedException();
} }
private dynamic GetHistoryHomePage() private dynamic GetHistoryHomePage()
{ {
return View["HistoryIndex.cshtml"]; return View["HistoryIndex.cshtml"];
} }
} }