vnext
Paul Schneider 8 years ago
parent 0582421523
commit b627544e4f
2 changed files with 22 additions and 5 deletions

@ -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<IViewComponentResult> InvokeAsync(long id)
{
Estimate estimate =
return await InvokeAsync(id,"Html");
}
public async Task<IViewComponentResult> 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);
}
);
}
}

@ -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; }
}
}
Loading…