forked from NetCoreApps/TemplatePages
/
CodePagePartials.cs
48 lines (43 loc) · 1.45 KB
/
CodePagePartials.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Linq;
using System.Collections.Generic;
using ServiceStack;
using ServiceStack.Script;
namespace SharpScript
{
[Page("navLinks")]
public class NavLinksPartial : SharpCodePage
{
string render(string PathInfo, Dictionary<string, object> links) => $@"
<ul>
{links.Map(entry => $@"<li class='{GetClass(PathInfo, entry.Key)}'>
<a href='{entry.Key}'>{entry.Value}</a>
</li>").Join("")}
</ul>";
string GetClass(string pathInfo, string url) => url == pathInfo ? "active" : "";
}
[Page("customerCard")]
public class CustomerCardPartial : SharpCodePage
{
public ICustomers Customers { get; set; }
string render(string customerId) => renderCustomer(Customers.GetCustomer(customerId));
string renderCustomer(Customer customer) => $@"
<table class='table table-bordered'>
<caption>{customer.CompanyName}</caption>
<thead class='thead-inverse'>
<tr>
<th>Address</th>
<th>Phone</th>
<th>Fax</th>
</tr>
</thead>
<tr>
<td>
{customer.Address}
{customer.City}, {customer.PostalCode}, {customer.Country}
</td>
<td>{customer.Phone}</td>
<td>{customer.Fax}</td>
</tr>
</table>";
}
}