{"id":4813,"date":"2021-03-31T09:04:48","date_gmt":"2021-03-31T08:04:48","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=4813"},"modified":"2022-07-25T08:31:51","modified_gmt":"2022-07-25T07:31:51","slug":"c-build-simple-html-table","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/c-build-simple-html-table\/","title":{"rendered":"C# Build Simple Html Table"},"content":{"rendered":"\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">[HttpGet(\"api\/snipper\/saldo\")]\npublic async Task&lt;IActionResult> GetSnipperSaldoInfoHtml()\n{\n\tvar info = await GetSnipperSaldoInfo();\n\tvar data = Select(\n\t\tSelect&lt;object>(\"Huidig snipper-saldo\", FormatNumber(info.SaldoNow)),\n\t\tSelect&lt;object>(\"Huidig tijd-voor-tijd saldo\", FormatNumber(info.SaldoTVT)),\n\t\tSelect&lt;object>(\"Saldo totaal dit jaar\", FormatNumber(info.SaldoTotalThisYear))\n\t);\n\treturn Content(GetHtmlTable(data), \"text\/html\");\n}\n\npublic static string FormatNumber(double d) => FormattableString.Invariant($\"{Math.Round(d, 2):0.00}\"); \n\npublic static IEnumerable&lt;T> Select&lt;T>(params T[] args) => args;\n\nprivate static string GetHtmlTable(IEnumerable&lt;IEnumerable&lt;object>> data)\n{\n\tvar sb = new StringBuilder();\n\tsb.AppendLine(\"&lt;style>table {width: 300px;} td:nth-child(2) {text-align:right;}&lt;\/style>\");\n\tsb.AppendLine($\"&lt;table>\");\n\tforeach(var row in data)\n\t{\n\t\tsb.AppendLine($\"&lt;tr>\");\n\t\tforeach (var cell in row)\n\t\t\tsb.AppendLine($\"&lt;td>{cell}&lt;\/td>\");\n\t\tsb.AppendLine($\"&lt;\/tr>\");\n\t}\n\tsb.AppendLine($\"&lt;\/table>\");\n\treturn sb.ToString();\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[6,4,1],"tags":[],"class_list":["post-4813","post","type-post","status-publish","format-standard","hentry","category-dotnet","category-programming","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/4813","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=4813"}],"version-history":[{"count":1,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/4813\/revisions"}],"predecessor-version":[{"id":4814,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/4813\/revisions\/4814"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=4813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=4813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=4813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}