From b627544e4fb47f3411efb838a13f2e4901685d06 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Wed, 30 Nov 2016 11:01:50 +0100 Subject: [PATCH] idem --- Yavsc/ViewComponents/EstimateViewComponent.cs | 23 +++++++++++++++---- .../ViewModels/Gen/PdfGenerationViewModel.cs | 4 ++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Yavsc/ViewComponents/EstimateViewComponent.cs b/Yavsc/ViewComponents/EstimateViewComponent.cs index 2de4c272..fe549b60 100644 --- a/Yavsc/ViewComponents/EstimateViewComponent.cs +++ b/Yavsc/ViewComponents/EstimateViewComponent.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Linq; +using System.Threading.Tasks; using Microsoft.AspNet.Mvc; using Microsoft.Data.Entity; using Yavsc.Models; @@ -16,9 +17,15 @@ namespace Yavsc.ViewComponents { this.dbContext = dbContext; } - public IViewComponentResult InvokeAsync(long id, bool toPdf = false) + public async Task InvokeAsync(long id) { - Estimate estimate = + return await InvokeAsync(id,"Html"); + } + + public async Task InvokeAsync(long id, string outputFormat ="Html") + { + return await Task.Run( ()=> { + Estimate estimate = dbContext.Estimates.Include(x => x.Query) .Include(x => x.Query.Client) .Include(x => x.Query.PerformerProfile) @@ -27,11 +34,15 @@ namespace Yavsc.ViewComponents .Include(e => e.Bill).FirstOrDefault(x => x.Id == id); if (estimate == null) throw new Exception("No data"); - if (toPdf) + + if (outputFormat == "LaTeX") { + return this.View("Estimate_tex", estimate); + } + else if (outputFormat == "Pdf") { + // Sorry for this code string tex = null; var oldWriter = ViewComponentContext.ViewContext.Writer; - using (var writer = new StringWriter()) { this.ViewComponentContext.ViewContext.Writer = writer; @@ -50,7 +61,9 @@ namespace Yavsc.ViewComponents BaseFileName = $"estimate-{id}" } ); } - return this.View("Estimate_tex", estimate); + return View("Default",estimate); + } + ); } } diff --git a/Yavsc/ViewModels/Gen/PdfGenerationViewModel.cs b/Yavsc/ViewModels/Gen/PdfGenerationViewModel.cs index 6c193de4..8253ade5 100644 --- a/Yavsc/ViewModels/Gen/PdfGenerationViewModel.cs +++ b/Yavsc/ViewModels/Gen/PdfGenerationViewModel.cs @@ -1,14 +1,18 @@ using System.ComponentModel.DataAnnotations; +using Microsoft.AspNet.Mvc.Rendering; namespace Yavsc.ViewModels.Gen { public class PdfGenerationViewModel { + [Required] public string TeXSource { get; set; } [Required] public string BaseFileName { get; set; } [Required] public string DestDir { get; set; } + public bool Generated { get; set; } + public HtmlString GenerationErrorMessage { get; set; } } } \ No newline at end of file