using System.Collections.Generic;
using RazorEngine.Templating;
public static void Main()
<title>Contract Execution Request</title>
body { font-family: Arial, sans-serif; }
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid #dddddd; text-align: left; padding: 8px; }
th { background-color: #f2f2f2; }
<p>Please execute the following contracts for the client @Model.ClientName.</p>
<p><strong>Currency Pair:</strong> @Model.CurrencyPair</p>
<p><strong>Value Date:</strong> @Model.ValueDate</p>
@if (Model.Deals != null && Model.Deals.Count > 1)
@foreach (var deal in Model.Deals)
<td>@(deal.IsBuying ? ""BUY"" : ""SELL"")</td>
<td>@deal.QuantitySelected.ToString(""N0"")</td>
<td>@deal.ContractRate.ToString(""N2"")</td>
@if (Model.Deals.Count > 1)
var typedModel = (ContractDetails)Model;
For a total of: @typedModel.Deals.Sum(d => d.QuantitySelected).ToString(""N0"")
<p>No deals to display.</p>
""ClientName"": ""Acme Corp"",
""CurrencyPair"": ""USD/CAD"",
""ValueDate"": ""2023-12-31"",
""QuantitySelected"": 100000,
""QuantitySelected"": 100000,
var model = JsonSerializer.Deserialize<ContractDetails>(jsonString);
var service = RazorEngineService.Create();
var emailBody = service.RunCompile(template, "templateKey", null, model);
Console.WriteLine(emailBody);
public string LegType { get; set; }
public bool IsBuying { get; set; }
public int QuantitySelected { get; set; }
public string Ccy1 { get; set; }
public double ContractRate { get; set; }
public class ContractDetails
public string ClientName { get; set; }
public string CurrencyPair { get; set; }
public string ValueDate { get; set; }
public List<Deal> Deals { get; set; }