Class with complex properties
I am new to FluentLiquid so I'm not sure if what I am doing should work or not. I'm trying to use a class with nested class properties. The example below is contrived to make my question easier to understand.
Here are the C# classes.
public class AccountStatusModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
public IEnumerable<string> InvoiceNumbers { get; set; }
public ContactInformation ContactInfo { get; set; }
public IEnumerable<Payment> InvoicePayments { get; set; }
}
public class ContactInformation
{
public string Email { get; set; }
public string PhoneNumber { get; set; }
}
public class Payment
{
public DateTime PaymentDate { get; set; }
public decimal PaymentAmount { get; set; }
}
And here is the email template. The simple properties for FirstName and LastName display correctly. So do the IEnumerable<string> values. However, the ContactInfo properties are blank and so are the InvoicePayments object properties. For the IEnumerable<Payment>, the loop does show a list item for each of the Payment items (simple bullet in this case) but the list item does not have the data for the Payment property values. That is, if the IEnumerable<Payment> has four items, I get four bullets but no text next to the bullets.
<p>
First Name: {{FirstName}} <br />
Last Name: {{LastName}}<br />
</p>
<p>
<h4>Contact Information</h4>
Email: {{ContactInfo.Email}} <br />
Phone: {{ContactInfo.PhoneNumber}} <br />
</p>
<p>
Here are your invoices and the payments that have been made towards them
<h4>Invoices</h4>
<ul>
{% for invoice in InvoiceNumbers %}
<li>{{invoice}}</li>
{% endfor %}
</ul>
</p>
<p>
<h4>Payments</h4>
<ul>
{% for p in InvoicePayments %}
<li>{{p.PaymentDate}} - {{p.PaymentAmount}}</li>
{% endfor %}
</ul>
</p>
My primary question is whether this package can handle the nested objects or not. If it can do that, what am I doing wrong with the template?
Did you "Include" the related properties in your query?
_context.AccountStatus
.Include(x => x.ContactInformation)
.Include(x => x.Payment)
.FirstOrDefault();
https://docs.microsoft.com/en-us/ef/core/querying/related-data/