diff --git a/Rotativa.AspNetCore.DemoApp/Controllers/HomeController.cs b/Rotativa.AspNetCore.DemoApp/Controllers/HomeController.cs index f5b36bb..e319696 100644 --- a/Rotativa.AspNetCore.DemoApp/Controllers/HomeController.cs +++ b/Rotativa.AspNetCore.DemoApp/Controllers/HomeController.cs @@ -2,6 +2,7 @@ using Rotativa.AspNetCore.DemoApp.Models; using System.Diagnostics; using Rotativa.AspNetCore.Options; +using System.Data.Common; namespace Rotativa.AspNetCore.DemoApp.Controllers { @@ -30,6 +31,22 @@ public IActionResult Privacy() return new ViewAsPdf(); } + public IActionResult EphemerideWithAction() + { + return new ActionAsPdf("Ephemeride", new { d=DateTime.Now , day= DateTime.Now.DayOfWeek.ToString() } ); + } + + public IActionResult Ephemeride( DateTime d, string day) + { + Ephemeride ephemeride = new Ephemeride(); + ephemeride.DateOfTheDay = d; + ephemeride.TheDayToday = day; + + ViewBag.testViewBag = new List { "val 1", " val 2" }; + + return View("EphemerideDemo", ephemeride); + } + public IActionResult ContactImage() { ViewData["Message"] = "Your contact page image."; diff --git a/Rotativa.AspNetCore.DemoApp/Models/Ephemeride.cs b/Rotativa.AspNetCore.DemoApp/Models/Ephemeride.cs new file mode 100644 index 0000000..c16eaff --- /dev/null +++ b/Rotativa.AspNetCore.DemoApp/Models/Ephemeride.cs @@ -0,0 +1,9 @@ +namespace Rotativa.AspNetCore.DemoApp.Models +{ + public class Ephemeride + { + public DateTime? DateOfTheDay { get; set; } + public string? TheDayToday { get; set; } + + } +} diff --git a/Rotativa.AspNetCore.DemoApp/Views/Home/EphemerideDemo.cshtml b/Rotativa.AspNetCore.DemoApp/Views/Home/EphemerideDemo.cshtml new file mode 100644 index 0000000..92aa1bd --- /dev/null +++ b/Rotativa.AspNetCore.DemoApp/Views/Home/EphemerideDemo.cshtml @@ -0,0 +1,26 @@ +@model Rotativa.AspNetCore.DemoApp.Models.Ephemeride + +@{ + ViewData["Title"] = "Ephemeride"; + List testViewBag = ViewBag.testViewBag as List; +} +

@ViewData["Title"]

+

@ViewData["Message"]

+ +
+

@Model.DateOfTheDay

+

@Model.TheDayToday

+
+ +
+

ViewBag Content :

+
    + @if (testViewBag != null) + { + foreach (var item in testViewBag) + { +
  • @item
  • + } + } +
+
\ No newline at end of file diff --git a/Rotativa.AspNetCore.DemoApp/Views/Shared/_Layout.cshtml b/Rotativa.AspNetCore.DemoApp/Views/Shared/_Layout.cshtml index e998670..c3c5099 100644 --- a/Rotativa.AspNetCore.DemoApp/Views/Shared/_Layout.cshtml +++ b/Rotativa.AspNetCore.DemoApp/Views/Shared/_Layout.cshtml @@ -34,6 +34,9 @@ + diff --git a/Rotativa.AspNetCore/ActionAsImage.cs b/Rotativa.AspNetCore/ActionAsImage.cs new file mode 100644 index 0000000..9a2b534 --- /dev/null +++ b/Rotativa.AspNetCore/ActionAsImage.cs @@ -0,0 +1,59 @@ +using System; +using Microsoft.AspNetCore.Http.Extensions; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Routing; +using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.DependencyInjection; + +namespace Rotativa.AspNetCore +{ + public class ActionAsImage : AsImageResultBase + { + private RouteValueDictionary _routeValuesDict; + private object _routeValues; + private string _action; + + public ActionAsImage(string action) : base() + { + _action = action; + } + + public ActionAsImage(string action, RouteValueDictionary routeValues) + : this(action) + { + _routeValuesDict = routeValues; + } + + public ActionAsImage(string action, object routeValues) + : this(action) + { + _routeValues = routeValues; + } + + protected override string GetUrl(ActionContext context) + { + var urlHelperFactory = context.HttpContext.RequestServices.GetRequiredService(); + var urlHelper = urlHelperFactory.GetUrlHelper(context); + + string actionUrl; + if (_routeValues == null) + { + actionUrl = urlHelper.Action(_action, _routeValuesDict); + } + else if (_routeValues != null) + { + actionUrl = urlHelper.Action(_action, _routeValues); + } + else + { + actionUrl = urlHelper.Action(_action); + } + + var currentUri = new Uri(context.HttpContext.Request.GetDisplayUrl()); + var authority = currentUri.GetComponents(UriComponents.StrongAuthority, UriFormat.Unescaped); + + var url = $"{context.HttpContext.Request.Scheme}://{authority}{actionUrl}"; + return url; + } + } +} diff --git a/Rotativa.AspNetCore/ActionAsPdf.cs b/Rotativa.AspNetCore/ActionAsPdf.cs new file mode 100644 index 0000000..06ca470 --- /dev/null +++ b/Rotativa.AspNetCore/ActionAsPdf.cs @@ -0,0 +1,59 @@ +using System; +using Microsoft.AspNetCore.Http.Extensions; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Routing; +using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.DependencyInjection; + +namespace Rotativa.AspNetCore +{ + public class ActionAsPdf : AsPdfResultBase + { + private RouteValueDictionary _routeValuesDict; + private object _routeValues; + private string _action; + + public ActionAsPdf(string action) : base() + { + _action = action; + } + + public ActionAsPdf(string action, RouteValueDictionary routeValues) + : this(action) + { + _routeValuesDict = routeValues; + } + + public ActionAsPdf(string action, object routeValues) + : this(action) + { + _routeValues = routeValues; + } + + protected override string GetUrl(ActionContext context) + { + var urlHelperFactory = context.HttpContext.RequestServices.GetRequiredService(); + var urlHelper = urlHelperFactory.GetUrlHelper(context); + + string actionUrl; + if (_routeValues == null) + { + actionUrl = urlHelper.Action(_action, _routeValuesDict); + } + else if (_routeValues != null) + { + actionUrl = urlHelper.Action(_action, _routeValues); + } + else + { + actionUrl = urlHelper.Action(_action); + } + + var currentUri = new Uri(context.HttpContext.Request.GetDisplayUrl()); + var authority = currentUri.GetComponents(UriComponents.StrongAuthority, UriFormat.Unescaped); + + var url = $"{context.HttpContext.Request.Scheme}://{authority}{actionUrl}"; + return url; + } + } +}