Razor Templates

This commit is contained in:
2023-03-08 01:29:57 +01:00
parent 78d2dc06d0
commit afef650b26
11 changed files with 355 additions and 278 deletions

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace WGneu.Documents {
public class Document {
public Document(string title) {
Title = title;
Header = "Winzergenossenschaft Matzen";
Footer = "Winzergenossenschaft für Matzen und Umgebung reg. Gen.m.b.H.";
Date = DateTime.Today;
}
public string Title { get; set; }
public string Header { get; set; }
public string Footer { get; set; }
public string FullDateString {
get {
return Date.ToString("dddd, d. MMMM yyyy");
}
}
public DateTime Date { get; set; }
private async Task<string> Render() {
if (this is BusinessLetter bl) {
return await Pdf.CompileRenderAsync("BusinessLetter.cshtml", bl);
} else if (this is BusinessDocument bd) {
return await Pdf.CompileRenderAsync("BusinessDocument.cshtml", bd);
} else {
return await Pdf.CompileRenderAsync("Document.cshtml", this);
}
}
private async Task<string> SaveHtml() {
await File.WriteAllTextAsync("razor_test.html", await Render());
return "";
}
public async Task<string> Save() {
await SaveHtml();
return "";
}
}
}