From 610a69a18ec54bd36e9d230447ce83e4603d86e0 Mon Sep 17 00:00:00 2001 From: "chris.watts90@outlook.com" Date: Mon, 26 Jun 2017 21:27:44 +0100 Subject: [PATCH] add method to generate a pdf file of the race session. this may move to api, not sure. --- .../RaceLapTimer/Modules/HistoryModule.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/RaceLapTimer/RaceLapTimer/Modules/HistoryModule.cs b/RaceLapTimer/RaceLapTimer/Modules/HistoryModule.cs index 3d9ceee..3a1a9cc 100644 --- a/RaceLapTimer/RaceLapTimer/Modules/HistoryModule.cs +++ b/RaceLapTimer/RaceLapTimer/Modules/HistoryModule.cs @@ -1,5 +1,8 @@ using System; +using System.Dynamic; +using System.IO; using Nancy; +using Nancy.ViewEngines; namespace RaceLapTimer.Modules { @@ -8,10 +11,36 @@ namespace RaceLapTimer.Modules public HistoryModule():base("/history") { 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() { + + return View["HistoryIndex.cshtml"]; } }