<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Coding for blazor apps and SolidWorks API]]></title><description><![CDATA[Working on learning to code using mainly C#.  Recording helpful things I have coded for future reference.]]></description><link>https://craigbrunton.social</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1706693329588/GqtO-cNZ7.png</url><title>Coding for blazor apps and SolidWorks API</title><link>https://craigbrunton.social</link></image><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Apr 2026 08:36:22 GMT</lastBuildDate><atom:link href="https://craigbrunton.social/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Blazor Navigation]]></title><description><![CDATA[The below shows ways to navigate other than using the menu.
Routing for Pages
The routing generally goes at the top of the razor file.
//In the razor page:
@page "/pagetonavigateto"

//With a parameter value
@page "/pagetonavigateto/{id:int}"  //if t...]]></description><link>https://craigbrunton.social/blazor-navigation</link><guid isPermaLink="true">https://craigbrunton.social/blazor-navigation</guid><category><![CDATA[blazor navigation]]></category><category><![CDATA[Blazor]]></category><category><![CDATA[Blazor Webassembly]]></category><dc:creator><![CDATA[Craig Brunton]]></dc:creator><pubDate>Thu, 15 Dec 2022 14:22:48 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1671114065945/7W_WkRsOu.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The below shows ways to navigate other than using the menu.</p>
<h3 id="heading-routing-for-pages">Routing for Pages</h3>
<p>The routing generally goes at the top of the razor file.</p>
<pre><code class="lang-csharp"><span class="hljs-comment">//In the razor page:</span>
@page <span class="hljs-string">"/pagetonavigateto"</span>

<span class="hljs-comment">//With a parameter value</span>
@page <span class="hljs-string">"/pagetonavigateto/{id:int}"</span>  <span class="hljs-comment">//if the id is a int there are various types you can use such as bool, string etc.</span>
</code></pre>
<h3 id="heading-using-ltagt-tags">Using &lt;a&gt; Tags</h3>
<pre><code class="lang-csharp">&lt;a href=<span class="hljs-string">"/pagetonavigateto/parametervalue"</span>&gt;Click Here&lt;/a&gt;
</code></pre>
<h3 id="heading-using-buttons">Using Buttons</h3>
<p>In the razor file to navigate from</p>
<pre><code class="lang-csharp">&lt;button <span class="hljs-keyword">class</span>=<span class="hljs-string">"btn btn-primary"</span> @onclick=<span class="hljs-string">"Method"</span>&gt;Click Here&lt;/button&gt;
</code></pre>
<p>In the razor code section or the base class file</p>
<pre><code class="lang-csharp"><span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">Method</span>(<span class="hljs-params"></span>)</span>
{
    NavigationManager.NavigateTo(<span class="hljs-string">"/pagetonavigateto/parametervalue"</span>);
}
</code></pre>
<p>You will also need to inject the NavigationManager into either the razor file or the base class file</p>
<pre><code class="lang-csharp"><span class="hljs-comment">//In the razor file</span>
@inject NavigationManager NavigationManager

<span class="hljs-comment">//In the base class file</span>
[<span class="hljs-meta">Inject</span>]
NavigationManager NavManager { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Dapper One-To-Many Multiple Tables]]></title><description><![CDATA[Today I was working on using Dapper to use a SELECT statement from an Order table but to JOIN to two other tables which were the Suppliers table and the OrderItems table.
The reason for this is to produce for a report list of all orders, the supplier...]]></description><link>https://craigbrunton.social/dapper-one-to-many-multiple-tables</link><guid isPermaLink="true">https://craigbrunton.social/dapper-one-to-many-multiple-tables</guid><category><![CDATA[SQL]]></category><category><![CDATA[Dapper]]></category><dc:creator><![CDATA[Craig Brunton]]></dc:creator><pubDate>Fri, 17 Jun 2022 09:21:34 GMT</pubDate><content:encoded><![CDATA[<p>Today I was working on using Dapper to use a SELECT statement from an Order table but to JOIN to two other tables which were the Suppliers table and the OrderItems table.</p>
<p>The reason for this is to produce for a report list of all orders, the supplier and the total cost.</p>
<p><a target="_blank" href="https://makolyte.com/csharp-map-query-results-to-multiple-objects-with-dapper/">Link to article this is taken from</a></p>
<h4 id="heading-table-structure">Table structure:</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655454004564/FvFxWzYFP.png" alt="tables.png" /></p>
<h4 id="heading-code-full-snippet">Code Full Snippet:</h4>
<p>The code below is in a Repository for Orders and is returning an Order model.</p>
<pre><code><span class="hljs-built_in">public</span> async Task&lt;<span class="hljs-keyword">Order</span>&gt; GetOrderAsync(<span class="hljs-type">int</span> orderId)
        {
            var query = @"SELECT * FROM Orders 
                INNER JOIN Suppliers ON Orders.SupplierId = Suppliers.Id 
                INNER JOIN OrderItems ON OrderItems.OrderId = @Id
                WHERE Orders.Id = @Id";

            var orderMap = <span class="hljs-built_in">new</span> <span class="hljs-keyword">Dictionary</span>&lt;<span class="hljs-type">int</span>, <span class="hljs-keyword">Order</span>&gt;();

            <span class="hljs-keyword">using</span> (var <span class="hljs-keyword">connection</span> = _context.CreateConnection())
            {
                await <span class="hljs-keyword">connection</span>.QueryAsync&lt;<span class="hljs-keyword">Order</span>, Supplier, OrderItem, <span class="hljs-keyword">Order</span>&gt;(query,
                    (<span class="hljs-keyword">order</span>, supplier, orderitem) =&gt;
                    {
                        <span class="hljs-keyword">order</span>.Supplier = supplier;

                        orderitem.OrderId = <span class="hljs-keyword">order</span>.Id;

                        <span class="hljs-keyword">if</span> (orderMap.TryGetValue(<span class="hljs-keyword">order</span>.Id, <span class="hljs-keyword">out</span> <span class="hljs-keyword">Order</span> existingOrder))
                        {
                            <span class="hljs-keyword">order</span> = existingOrder;
                        }
                        <span class="hljs-keyword">else</span>
                        {
                            <span class="hljs-keyword">order</span>.OrderItems = <span class="hljs-built_in">new</span> List&lt;OrderItem&gt;();
                            orderMap.<span class="hljs-keyword">Add</span>(<span class="hljs-keyword">order</span>.Id, <span class="hljs-keyword">order</span>);
                        }

                        <span class="hljs-keyword">order</span>.OrderItems.<span class="hljs-keyword">Add</span>(orderitem);
                        <span class="hljs-keyword">return</span> <span class="hljs-keyword">order</span>;
                    },
                    param: <span class="hljs-built_in">new</span> { Id = orderId });

                //<span class="hljs-keyword">get</span> the <span class="hljs-keyword">order</span> <span class="hljs-keyword">object</span> <span class="hljs-keyword">from</span> the <span class="hljs-keyword">dictionary</span>
                <span class="hljs-keyword">Order</span> orderToReturn = <span class="hljs-built_in">new</span> <span class="hljs-keyword">Order</span>();
                orderToReturn = orderMap[orderId];
                <span class="hljs-keyword">return</span> orderToReturn;
            }
        }
</code></pre><h4 id="heading-order-model">Order Model:</h4>
<pre><code><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Order</span>
    {
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> Id { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> SupplierId { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
        <span class="hljs-keyword">public</span> Supplier Supplier { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
        <span class="hljs-keyword">public</span> DateTime OrderDate { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }  
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span>? Comments { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">List</span>&lt;<span class="hljs-title">OrderItem</span>&gt; OrderItems</span> { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; } = <span class="hljs-keyword">new</span> List&lt;OrderItem&gt;();
    }
</code></pre><p> I will try break down the code mainly to help me ensure I understand it but feel free to correct me below in the comments or if there is a better way of doign what I am then again feel free to comment below.</p>
<pre><code>var query = @"<span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> Orders 
                <span class="hljs-keyword">INNER</span> <span class="hljs-keyword">JOIN</span> Suppliers <span class="hljs-keyword">ON</span> Orders.SupplierId = Suppliers.Id 
                <span class="hljs-keyword">INNER</span> <span class="hljs-keyword">JOIN</span> OrderItems <span class="hljs-keyword">ON</span> OrderItems.OrderId = @<span class="hljs-keyword">Id</span>
                <span class="hljs-keyword">WHERE</span> Orders.Id = @<span class="hljs-keyword">Id</span><span class="hljs-string">";</span>
</code></pre><p>This code is just a standard SELECT statement with INNER JOIN on a Suppliers and OrderItems table.  The reason for the Suppliers join is in order to get the supplier and the OrderItems in order to get all items in the order.  It then selects the correct order based on the Id passed.</p>
<pre><code> <span class="hljs-keyword">var</span> orderMap <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> Dictionary<span class="hljs-operator">&lt;</span><span class="hljs-keyword">int</span>, Order<span class="hljs-operator">&gt;</span>();
</code></pre><p>Here we are creating a new dictionary where int will be the order Id passed and then an Order object.</p>
<pre><code> await connection.QueryAsync&lt;Order, Supplier, OrderItem, Order<span class="hljs-operator">&gt;</span>(query,
                    (order, supplier, orderitem) <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span>
</code></pre><p>This code take from the link above just with object names modified:</p>
<blockquote>
<p>Query means first map the columns to an Order object, then a Customer object, then a OrderItem object, and finally return IEnumerable.</p>
</blockquote>
<pre><code>order.Supplier <span class="hljs-operator">=</span> supplier;
orderitem.OrderId <span class="hljs-operator">=</span> order.Id;
</code></pre><p>Here I am simplying settign the Supplier for the order and the orderId for the OrderItem.</p>
<pre><code><span class="hljs-keyword">if</span> (orderMap.TryGetValue(order.Id, out Order existingOrder))
{
    order <span class="hljs-operator">=</span> existingOrder;
}
<span class="hljs-keyword">else</span>
{
    order.OrderItems <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> List<span class="hljs-operator">&lt;</span>OrderItem<span class="hljs-operator">&gt;</span>();
    orderMap.Add(order.Id, order);
}
</code></pre><p>So here I am checking in the dictionary if the Order exists as dapper will map the OrderItems columns to a new Order object for each row it finds therefore we need to de-dupe to keep track of the unique order otherwise if you have three OrderItems it will create three entries in the dictionary one for each OrderItem rather than have one Order with a list of OrderItems.</p>
<p>So if the order exists then it simply saves as the existingOrder.</p>
<p>If it does not exist then it creates a new list of OrderItem and maps to the order in the dictionary.</p>
<p>I am not sure I have this part 100% correct so feel free to correct me.  I am going to go through it in more detail to try to ensure fully understand it.</p>
<pre><code><span class="hljs-keyword">order</span>.OrderItems.<span class="hljs-keyword">Add</span>(orderitem);
 <span class="hljs-keyword">return</span> <span class="hljs-keyword">order</span>;
</code></pre><p>Here thecode is adding the orderitem to the list of OrderItems in the order and then returns the order from it.</p>
<pre><code>param: <span class="hljs-keyword">new</span> { Id <span class="hljs-operator">=</span> orderId });
</code></pre><p>Here we are adding a parameter for the order Id in order to get the correct order.  This bit when I was doing the code I missed out and if you do then it will error stating you must declare the scalar variable.  This took me a few hours to figure out so it seems what looks easy is often what gives you the most headaches.</p>
<pre><code><span class="hljs-keyword">Order</span> orderToReturn = <span class="hljs-built_in">new</span> <span class="hljs-keyword">Order</span>();
orderToReturn = orderMap[orderId];
<span class="hljs-keyword">return</span> orderToReturn;
</code></pre><p>This section of code takes the entry in the dictionary as there should only be one but you could error check for this.  As the dictionary wants to return a list I cannot return from the method just a single Order without putting the dciotnary value into an Order object then returning this.</p>
<h4 id="heading-result">Result</h4>
<pre><code>{
  <span class="hljs-attr">"id"</span>: <span class="hljs-number">166</span>,
  <span class="hljs-attr">"supplierId"</span>: <span class="hljs-number">2</span>,
  <span class="hljs-attr">"supplierName"</span>: <span class="hljs-string">"NCS"</span>,
  <span class="hljs-attr">"orderDate"</span>: <span class="hljs-string">"2021-09-26T00:00:00"</span>,
  <span class="hljs-attr">"comments"</span>: <span class="hljs-literal">null</span>,
  <span class="hljs-attr">"orderItems"</span>: [
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">655</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"quam. Pellentesque habitant morbi tristique"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">50</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">29.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">1499.5</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1151</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"dis parturient montes, nascetur ridiculus"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">2</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">38</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">76</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1824</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Does this add and update the order page."</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">5000</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">9.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">49950</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1825</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Does this add and update the order page.  Does this work."</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">5000</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">9.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">49950</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1826</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Does this now work?"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">55</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">1.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">109.45</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1827</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Does this now work?"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">55</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">1.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">109.45</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1828</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Does this now work?"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">55</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">1.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">109.45</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1829</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Does this now work?"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">55</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">1.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">109.45</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1830</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Does this now work?"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">55</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">1.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">109.45</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1831</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Does this now work?"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">55</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">1.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">109.45</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1832</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Does this now work?"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">55</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">1.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">109.45</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1833</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Does this now work?"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">55</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">1.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">109.45</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1834</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Does this now work?"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">55</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">1.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">109.45</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1835</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Does this now work?"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">55</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">1.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">109.45</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1836</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Does this now work?"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">55</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">1.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">109.45</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1837</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Does this now work?"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">55</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">1.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">109.45</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1838</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Does this now work?"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">55</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">1.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">109.45</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1839</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Does this now work?"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">55</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">1.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">109.45</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1854</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Testing toast"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">5</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">1.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">9.95</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1859</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Item god knows"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">5</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">3.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">19.95</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1860</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Another"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">5</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">2.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">14.95</span>
    },
    {
      <span class="hljs-attr">"id"</span>: <span class="hljs-number">1861</span>,
      <span class="hljs-attr">"description"</span>: <span class="hljs-string">"hh"</span>,
      <span class="hljs-attr">"qty"</span>: <span class="hljs-number">5</span>,
      <span class="hljs-attr">"price"</span>: <span class="hljs-number">3.99</span>,
      <span class="hljs-attr">"totalPrice"</span>: <span class="hljs-number">19.95</span>
    }
  ],
  <span class="hljs-attr">"orderCode"</span>: <span class="hljs-string">"IT-CRAIG-0166"</span>
}
</code></pre><p>The output is a little different to the models above as I have a mapping to a different model as below:</p>
<pre><code><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">OrderAndItemsDto</span>
{
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> Id { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> SupplierId { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> SupplierName { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
    <span class="hljs-keyword">public</span> DateTime OrderDate { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span>? Comments { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">List</span>&lt;<span class="hljs-title">OrderItemDto</span>&gt; OrderItems</span> { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; } = <span class="hljs-keyword">new</span> List&lt;OrderItemDto&gt;();

    <span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> OrderCode
    {
        <span class="hljs-keyword">get</span>
        {
            <span class="hljs-keyword">return</span> <span class="hljs-string">$"IT-CRAIG-<span class="hljs-subst">{Id.ToString(<span class="hljs-string">"0000"</span>)}</span>"</span>;
        }
    }
}
</code></pre>]]></content:encoded></item><item><title><![CDATA[Blazor Custom Radio Buttons]]></title><description><![CDATA[For a project I was looking at radio buttons but none seem to suit what I was looking for so I decided to create my own custom component to achieve what I needed.
This may not be the bes to rmost efficent way so please feel free to comment a better m...]]></description><link>https://craigbrunton.social/blazor-custom-radio-buttons</link><guid isPermaLink="true">https://craigbrunton.social/blazor-custom-radio-buttons</guid><category><![CDATA[Blazor ]]></category><category><![CDATA[CSS]]></category><dc:creator><![CDATA[Craig Brunton]]></dc:creator><pubDate>Tue, 02 Nov 2021 21:53:36 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1635390174625/bsTfYVdo_.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>For a project I was looking at radio buttons but none seem to suit what I was looking for so I decided to create my own custom component to achieve what I needed.</p>
<p>This may not be the bes to rmost efficent way so please feel free to comment a better method or a way to improve what I have done.</p>
<p>The code is not generic which is what I would like to do at some point if possible but for now it is not required for this project.</p>
<p>The styling is not what I want to to look like but can be worked.</p>
<p>The project has a requirnment for each maintenance request that risk levels can be selected from High "H", medium "M" and low "L".  There is a number of risks depending on the type or request either general or plant.</p>
<p>My structure is that there is a maintenance request with a unique ID and a Risk table with the risks for the type of maintenance request.  From here there is a table that has two FK which are the risk ID and maintenance request ID with a column string which is set to one of the risk level either "H", "M"  or "L".</p>
<p>The reason for also doing it this way is that more risks could be added over time so I wanted to implement a way for more to be added without the need to alter the code etc.</p>
<p>Video of the component in action.  The styling is not complete and has work to do but the functionality is there.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/90DqVYQ1qzo">https://youtu.be/90DqVYQ1qzo</a></div>
<p>Blazor Component - Full</p>
<pre><code>@using SACOMaintenance.Common.ModelDB
@using System.Collections.ObjectModel;
@using System;

&lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"container-full"</span>&gt;
    &lt;RadzenFieldset Text=<span class="hljs-string">"Risks"</span>&gt;
        &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"inner-radio-container"</span>&gt;
        @foreach (<span class="hljs-keyword">var</span> item <span class="hljs-keyword">in</span> ItemsChosen)
        {

            &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"container-outer"</span>&gt;
                &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"row"</span>&gt;
                    @foreach (<span class="hljs-keyword">var</span> riskItem <span class="hljs-keyword">in</span> Risks)
                    {
                        <span class="hljs-keyword">if</span> (riskItem.Id == item.RiskId)
                        {
                            &lt;label&gt;@riskItem.RiskName&lt;/label&gt;
                        }
                    }
                &lt;/div&gt;
                &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"row"</span>&gt;
                    &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"input-container"</span>&gt;
                        &lt;input name=<span class="hljs-string">"@item.RiskId"</span> type=<span class="hljs-string">"radio"</span> id=<span class="hljs-string">"H"</span> <span class="hljs-keyword">class</span>=<span class="hljs-string">"radio-button-H"</span>
                               <span class="hljs-keyword">value</span>=<span class="hljs-string">"H"</span> <span class="hljs-keyword">checked</span>=<span class="hljs-string">"@(item.Level.Equals("</span>H<span class="hljs-string">"))"</span>
                               @onchange=<span class="hljs-string">"_ =&gt; HandleChangeHigh(item)"</span> /&gt;
                        &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"radio-tile-H"</span>&gt;
                            &lt;label&gt;H&lt;/label&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                    &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"input-container"</span>&gt;
                        &lt;input name=<span class="hljs-string">"@item.RiskId"</span> type=<span class="hljs-string">"radio"</span> id=<span class="hljs-string">"M"</span> <span class="hljs-keyword">class</span>=<span class="hljs-string">"radio-button-M"</span>
                               <span class="hljs-keyword">value</span>=<span class="hljs-string">"H"</span> <span class="hljs-keyword">checked</span>=<span class="hljs-string">"@(item.Level.Equals("</span>M<span class="hljs-string">"))"</span>
                               @onchange=<span class="hljs-string">"_ =&gt; HandleChangeMedium(item)"</span> /&gt;
                        &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"radio-tile-M"</span>&gt;
                            &lt;label&gt;M&lt;/label&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                    &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"input-container"</span>&gt;
                        &lt;input name=<span class="hljs-string">"@item.RiskId"</span> type=<span class="hljs-string">"radio"</span> id=<span class="hljs-string">"L"</span> <span class="hljs-keyword">class</span>=<span class="hljs-string">"radio-button-L"</span>
                               <span class="hljs-keyword">value</span>=<span class="hljs-string">"H"</span> <span class="hljs-keyword">checked</span>=<span class="hljs-string">"@(item.Level.Equals("</span>L<span class="hljs-string">"))"</span>
                               @onchange=<span class="hljs-string">"_ =&gt; HandleChangeLow(item)"</span> /&gt;
                        &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"radio-tile-L"</span>&gt;
                            &lt;label&gt;L&lt;/label&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        }
        &lt;/div&gt;
    &lt;/RadzenFieldset&gt;


        &lt;/div&gt;

        @code{
            [<span class="hljs-meta">Parameter</span>]
            <span class="hljs-keyword">public</span> ObservableCollection&lt;Risk&gt; Risks { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }

            [<span class="hljs-meta">Parameter</span>]
            <span class="hljs-keyword">public</span> List&lt;MaintRequestInitiationRisk&gt; ItemsChosen { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; } = <span class="hljs-keyword">new</span>();

            [<span class="hljs-meta">Parameter</span>]
            <span class="hljs-keyword">public</span> EventCallback&lt;List&lt;MaintRequestInitiationRisk&gt;&gt; ItemsChosenChanged { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }

            <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">HandleChangeHigh</span>(<span class="hljs-params">MaintRequestInitiationRisk item</span>)</span>
            {

                item.Level = <span class="hljs-string">"H"</span>;
                ItemsChosenChanged.InvokeAsync(ItemsChosen);
            }

            <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">HandleChangeMedium</span>(<span class="hljs-params">MaintRequestInitiationRisk item</span>)</span>
            {

                item.Level = <span class="hljs-string">"M"</span>;
                ItemsChosenChanged.InvokeAsync(ItemsChosen);
            }

            <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">HandleChangeLow</span>(<span class="hljs-params">MaintRequestInitiationRisk item</span>)</span>
            {

                item.Level = <span class="hljs-string">"L"</span>;
                ItemsChosenChanged.InvokeAsync(ItemsChosen);
            }
        }
</code></pre><p>Breaking the above code down into sections to explain what each part is doing.</p>
<pre><code>[<span class="hljs-meta">Parameter</span>]
            <span class="hljs-keyword">public</span> ObservableCollection&lt;Risk&gt; Risks { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }

            [<span class="hljs-meta">Parameter</span>]
            <span class="hljs-keyword">public</span> List&lt;MaintRequestInitiationRisk&gt; ItemsChosen { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; } = <span class="hljs-keyword">new</span>();

            [<span class="hljs-meta">Parameter</span>]
            <span class="hljs-keyword">public</span> EventCallback&lt;List&lt;MaintRequestInitiationRisk&gt;&gt; ItemsChosenChanged { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
</code></pre><p>The ObservableCollection Risks is getting all off the risks that there are so that the risk name can be gotten.</p>
<p>List ItemsChosen are the risks that are for the type of maintenance request and it has the risk level set to either H, M or L.</p>
<p>public EventCallback&gt; ItemsChosenChanged is a callback to a list of risks and what the risk level is so that any changes to the risk level of any of the risks are passed back in order to update the model and database table.</p>
<p>This code snippet starts to loop through the risks that are associated with the request.</p>
<pre><code><span class="hljs-meta">@foreach</span> (<span class="hljs-keyword">var</span> item <span class="hljs-keyword">in</span> ItemsChosen)
        {
</code></pre><p>This code snippet below loops through the risks and then checks to see if the risk Id is the same as the current chosen risk and of so then it outputs the Risk Name</p>
<pre><code><span class="hljs-meta">@foreach</span> (<span class="hljs-keyword">var</span> riskItem <span class="hljs-keyword">in</span> Risks)
                    {
                        <span class="hljs-keyword">if</span> (riskItem.Id == item.RiskId)
                        {
                            &lt;label&gt;<span class="hljs-meta">@riskItem</span>.RiskName&lt;/label&gt;
                        }
                    }
</code></pre><p>This next code snippet sets the RiskId and the imput as a radio button.  Then on check it calls a method to change the risk level.</p>
<pre><code>&lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"input-container"</span>&gt;
                        &lt;input name=<span class="hljs-string">"@item.RiskId"</span> type=<span class="hljs-string">"radio"</span> id=<span class="hljs-string">"H"</span> <span class="hljs-keyword">class</span>=<span class="hljs-string">"radio-button-H"</span>
                               <span class="hljs-keyword">value</span>=<span class="hljs-string">"H"</span> <span class="hljs-keyword">checked</span>=<span class="hljs-string">"@(item.Level.Equals("</span>H<span class="hljs-string">"))"</span>
                               @onchange=<span class="hljs-string">"_ =&gt; HandleChangeHigh(item)"</span> /&gt;
                        &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"radio-tile-H"</span>&gt;
                            &lt;label&gt;H&lt;/label&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
</code></pre><p>There is one for each of the risk levels.</p>
<p>The implementation in blazor for the component is where the Risks and Risk Items lists are passed to the component as parameters.</p>
<pre><code><span class="hljs-tag">&lt;<span class="hljs-name">RequestRiskChoice</span> @<span class="hljs-attr">bind-ItemsChosen</span>=<span class="hljs-string">"maintReqInitation.RiskListsChosen"</span> <span class="hljs-attr">Risks</span>=<span class="hljs-string">"maintReqInitation.Risks"</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">RequestRiskChoice</span>&gt;</span>
</code></pre><p>CSS Code for styling.</p>
<pre><code><span class="hljs-selector-class">.container-full</span> {
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">flex-direction</span>: column;
    <span class="hljs-attribute">align-items</span>: center;
    <span class="hljs-attribute">justify-content</span>: center;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
}

<span class="hljs-selector-class">.inner-radio-container</span> {
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">justify-content</span>: center;
    <span class="hljs-attribute">align-items</span>: center;
    <span class="hljs-attribute">flex-wrap</span>:wrap;
}

<span class="hljs-selector-class">.container-outer</span> {
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">flex-wrap</span>: wrap;
    <span class="hljs-attribute">flex-direction</span>: column;
    <span class="hljs-attribute">align-items</span>: center;
    <span class="hljs-attribute">justify-content</span>: center;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">25%</span>;
    <span class="hljs-attribute">background-color</span>: lightgray;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">5px</span> <span class="hljs-number">5px</span> <span class="hljs-number">5px</span> <span class="hljs-number">5px</span>;
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">5px</span> <span class="hljs-number">5px</span> <span class="hljs-number">5px</span> <span class="hljs-number">5px</span>;
}

<span class="hljs-selector-class">.input-container</span> {
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">position</span>: relative;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">4rem</span>;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">4rem</span>;
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">0.5rem</span>;
}

    <span class="hljs-selector-class">.radio-button-H</span>, <span class="hljs-selector-class">.radio-button-M</span>, <span class="hljs-selector-class">.radio-button-L</span> {
        <span class="hljs-attribute">opacity</span>: <span class="hljs-number">0</span>;
        <span class="hljs-attribute">position</span>: absolute;
        <span class="hljs-attribute">top</span>: <span class="hljs-number">0</span>;
        <span class="hljs-attribute">left</span>: <span class="hljs-number">0</span>;
        <span class="hljs-attribute">height</span>: <span class="hljs-number">100%</span>;
        <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
        <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
        <span class="hljs-attribute">cursor</span>: pointer;
    }

    <span class="hljs-selector-class">.radio-tile-H</span>, <span class="hljs-selector-class">.radio-tile-M</span>, <span class="hljs-selector-class">.radio-tile-L</span> {
        <span class="hljs-attribute">display</span>: flex;
        <span class="hljs-attribute">flex-direction</span>: column;
        <span class="hljs-attribute">align-items</span>: center;
        <span class="hljs-attribute">justify-content</span>: center;
        <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
        <span class="hljs-attribute">height</span>: <span class="hljs-number">100%</span>;
        <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid red;
        <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">5px</span>;
        <span class="hljs-attribute">padding</span>: <span class="hljs-number">1rem</span>;
        <span class="hljs-attribute">transition</span>: transform <span class="hljs-number">300ms</span> ease;
    }

<span class="hljs-selector-class">.radio-tile-M</span> {
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">flex-direction</span>: column;
    <span class="hljs-attribute">align-items</span>: center;
    <span class="hljs-attribute">justify-content</span>: center;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid yellow;
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">5px</span>;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">1rem</span>;
    <span class="hljs-attribute">transition</span>: transform <span class="hljs-number">300ms</span> ease;
}
<span class="hljs-selector-class">.radio-tile-L</span> {
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">flex-direction</span>: column;
    <span class="hljs-attribute">align-items</span>: center;
    <span class="hljs-attribute">justify-content</span>: center;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid green;
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">5px</span>;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">1rem</span>;
    <span class="hljs-attribute">transition</span>: transform <span class="hljs-number">300ms</span> ease;
}
    <span class="hljs-selector-class">.radio-button-H</span><span class="hljs-selector-pseudo">:checked</span> + <span class="hljs-selector-class">.radio-tile-H</span> {
        <span class="hljs-attribute">background-color</span>: red;
        <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid red;
        <span class="hljs-attribute">color</span>: white;
        <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">scale</span>(<span class="hljs-number">1.1</span>, <span class="hljs-number">1.1</span>);
    }

    <span class="hljs-selector-class">.radio-tile-label-H</span> {
        <span class="hljs-attribute">color</span>: white;
        <span class="hljs-attribute">background-color</span>: red;
    }

    <span class="hljs-selector-class">.radio-button-M</span><span class="hljs-selector-pseudo">:checked</span> + <span class="hljs-selector-class">.radio-tile-M</span> {
        <span class="hljs-attribute">background-color</span>: yellow;
        <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid yellow;
        <span class="hljs-attribute">color</span>: white;
        <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">scale</span>(<span class="hljs-number">1.1</span>, <span class="hljs-number">1.1</span>);
    }

    <span class="hljs-selector-class">.radio-tile-label-M</span> {
        <span class="hljs-attribute">color</span>: black;
        <span class="hljs-attribute">background-color</span>: yellow;
    }

    <span class="hljs-selector-class">.radio-button-L</span><span class="hljs-selector-pseudo">:checked</span> + <span class="hljs-selector-class">.radio-tile-L</span> {
        <span class="hljs-attribute">background-color</span>: green;
        <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid green;
        <span class="hljs-attribute">color</span>: white;
        <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">scale</span>(<span class="hljs-number">1.1</span>, <span class="hljs-number">1.1</span>);
    }

    <span class="hljs-selector-class">.radio-tile-label-L</span> {
        <span class="hljs-attribute">color</span>: white;
        <span class="hljs-attribute">background-color</span>: green;
    }
</code></pre>]]></content:encoded></item><item><title><![CDATA[Blazor - Downloading Excel File]]></title><description><![CDATA[Working on a project at work I have a requirnment for creating and downloading an excel file.
This has proven to be confusing but in the end with the help of our friend google I managed to find and implement the code needed using Javascript in blazor...]]></description><link>https://craigbrunton.social/blazor-downloading-excel-file</link><guid isPermaLink="true">https://craigbrunton.social/blazor-downloading-excel-file</guid><category><![CDATA[Blazor ]]></category><category><![CDATA[C#]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Craig Brunton]]></dc:creator><pubDate>Tue, 19 Oct 2021 12:15:10 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1634645611002/PT_TXKoll.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Working on a project at work I have a requirnment for creating and downloading an excel file.</p>
<p>This has proven to be confusing but in the end with the help of our friend google I managed to find and implement the code needed using Javascript in blazor to do this so adding here for my memory and just in case i tmay help anyone else in the future.</p>
<p>First the Javascript file method:</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">saveAsFile</span>(<span class="hljs-params">filename, bytesBase64</span>) </span>{
    <span class="hljs-keyword">var</span> link <span class="hljs-operator">=</span> document.createElement(<span class="hljs-string">'a'</span>);
    link.download <span class="hljs-operator">=</span> filename;
    link.href <span class="hljs-operator">=</span> <span class="hljs-string">"data:application/octet-stream;base64,"</span> <span class="hljs-operator">+</span> bytesBase64;
    document.body.appendChild(link); <span class="hljs-comment">// Needed for Firefox</span>
    link.click();
    document.body.removeChild(link);
}
</code></pre><p>Then in the blazor file or class file you would call as</p>
<pre><code>await JSRuntime.InvokeAsync&lt;object<span class="hljs-operator">&gt;</span>(<span class="hljs-string">"saveAsFile"</span>, fileName, Convert.ToBase64String(content));
</code></pre><p>It needs (if I have understood this correctly) the content to be byte format so for my excel file I used ClosedXML to create the excel file then at the end exported so it donwloaded to the users selected download location.</p>
<p>What I essentially have in my project is a:</p>
<ul>
<li><p>Razor page which has a table of requests with an export button which calls a method from a custom excel class.  This custom excel class is injected into this razor page.</p>
</li>
<li><p>The custom excel class uses ClosedXML to create the excel file as required with data, formatting etc.</p>
</li>
<li><p>In the startup the custom excel class is injected as a service so the razor page can inject it.</p>
</li>
</ul>
<p>Custom Class Code:</p>
<pre><code><span class="hljs-keyword">using</span> <span class="hljs-title">System</span>.<span class="hljs-title">Threading</span>.<span class="hljs-title">Tasks</span>;
<span class="hljs-keyword">using</span> <span class="hljs-title">System</span>.<span class="hljs-title">IO</span>;
<span class="hljs-keyword">using</span> <span class="hljs-title">Microsoft</span>.<span class="hljs-title">JSInterop</span>;


namespace SACOMaintenance.Blazor.Server.Services
{
    <span class="hljs-keyword">public</span> class MaintenanceRequestsExcel
    {

        <span class="hljs-keyword">private</span> readonly IJSRuntime JSRuntime;

        <span class="hljs-keyword">public</span> MaintenanceRequestsExcel(IJSRuntime jSRuntime)
        {
            JSRuntime <span class="hljs-operator">=</span> jSRuntime;
        }

            <span class="hljs-keyword">using</span> (<span class="hljs-title"><span class="hljs-keyword">var</span></span> <span class="hljs-title">workbook</span> <span class="hljs-operator">=</span> <span class="hljs-title"><span class="hljs-keyword">new</span></span> <span class="hljs-title">XLWorkbook</span>())
            {
                <span class="hljs-title"><span class="hljs-keyword">var</span></span> <span class="hljs-title">worksheet</span> <span class="hljs-operator">=</span> <span class="hljs-title">workbook</span>.<span class="hljs-title">Worksheets</span>.<span class="hljs-title">Add</span>("<span class="hljs-title">Maint</span> <span class="hljs-title">Requests</span> <span class="hljs-title">All</span>");

                worksheet.Cell(<span class="hljs-string">"A1"</span>).Value <span class="hljs-operator">=</span> <span class="hljs-string">"All Maintenance Requests"</span>;
                worksheet.Cell(<span class="hljs-string">"A1"</span>).Style.Font.Bold <span class="hljs-operator">=</span> <span class="hljs-literal">true</span>;
                worksheet.Cell(<span class="hljs-string">"A1"</span>).Style.Font.FontSize <span class="hljs-operator">=</span> <span class="hljs-number">20</span>;
                worksheet.Range(<span class="hljs-string">"A1"</span>, <span class="hljs-string">"E1"</span>).Merge(<span class="hljs-literal">true</span>);

                worksheet.Cell(<span class="hljs-string">"A2"</span>).Value <span class="hljs-operator">=</span> <span class="hljs-string">"Id"</span>;
                worksheet.Cell(<span class="hljs-string">"A2"</span>).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);
                worksheet.Cell(<span class="hljs-string">"A2"</span>).Style.Font.Bold <span class="hljs-operator">=</span> <span class="hljs-literal">true</span>;

                worksheet.Cell(<span class="hljs-string">"B2"</span>).Value <span class="hljs-operator">=</span> <span class="hljs-string">"Details"</span>;
                worksheet.Cell(<span class="hljs-string">"B2"</span>).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);
                worksheet.Cell(<span class="hljs-string">"B2"</span>).Style.Font.Bold <span class="hljs-operator">=</span> <span class="hljs-literal">true</span>;

                worksheet.Cell(<span class="hljs-string">"C2"</span>).Value <span class="hljs-operator">=</span> <span class="hljs-string">"Date Raised"</span>;
                worksheet.Cell(<span class="hljs-string">"C2"</span>).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);
                worksheet.Cell(<span class="hljs-string">"C2"</span>).Style.Font.Bold <span class="hljs-operator">=</span> <span class="hljs-literal">true</span>;

                worksheet.Cell(<span class="hljs-string">"D2"</span>).Value <span class="hljs-operator">=</span> <span class="hljs-string">"Equipment Name"</span>;
                worksheet.Cell(<span class="hljs-string">"D2"</span>).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);
                worksheet.Cell(<span class="hljs-string">"D2"</span>).Style.Font.Bold <span class="hljs-operator">=</span> <span class="hljs-literal">true</span>;

                worksheet.Cell(<span class="hljs-string">"E2"</span>).Value <span class="hljs-operator">=</span> <span class="hljs-string">"Status"</span>;
                worksheet.Cell(<span class="hljs-string">"E2"</span>).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);
                worksheet.Cell(<span class="hljs-string">"E2"</span>).Style.Font.Bold <span class="hljs-operator">=</span> <span class="hljs-literal">true</span>;

                worksheet.Column(<span class="hljs-number">1</span>).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);
                worksheet.Column(<span class="hljs-number">3</span>).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);
                worksheet.Column(<span class="hljs-number">4</span>).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);
                worksheet.Column(<span class="hljs-number">5</span>).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);

                worksheet.Range(<span class="hljs-string">"A2"</span>, <span class="hljs-string">"E2"</span>).SetAutoFilter();

                <span class="hljs-comment">//loop through the collection and put the items in columns then increment to the next row</span>
                <span class="hljs-keyword">var</span> i <span class="hljs-operator">=</span> <span class="hljs-number">3</span>; <span class="hljs-comment">//declare the row number to start</span>

                <span class="hljs-comment">//loop through the items in the list</span>
                foreach(<span class="hljs-keyword">var</span> item in exportList)
                {
                    worksheet.Cell(<span class="hljs-string">"A"</span> <span class="hljs-operator">+</span> i).Value <span class="hljs-operator">=</span> item.Id;
                    worksheet.Cell(<span class="hljs-string">"B"</span> <span class="hljs-operator">+</span> i).Value <span class="hljs-operator">=</span> item.RequestDetails;
                    worksheet.Cell(<span class="hljs-string">"C"</span> <span class="hljs-operator">+</span> i).Value <span class="hljs-operator">=</span> item.DateRaised;
                    worksheet.Cell(<span class="hljs-string">"D"</span> <span class="hljs-operator">+</span> i).Value <span class="hljs-operator">=</span> item.Equipment.Name;
                    worksheet.Cell(<span class="hljs-string">"E"</span> <span class="hljs-operator">+</span> i).Value <span class="hljs-operator">=</span> item.Status.StatusName;
                    i<span class="hljs-operator">+</span><span class="hljs-operator">+</span>;
                }

                worksheet.Columns(<span class="hljs-string">"A"</span>, <span class="hljs-string">"E"</span>).AdjustToContents();

                <span class="hljs-comment">//Download the excel file to the users download default lcoation</span>
                <span class="hljs-keyword">using</span> (<span class="hljs-title"><span class="hljs-keyword">var</span></span> <span class="hljs-title">stream</span> <span class="hljs-operator">=</span> <span class="hljs-title"><span class="hljs-keyword">new</span></span> <span class="hljs-title">MemoryStream</span>())
                {
                    <span class="hljs-title">workbook</span>.<span class="hljs-title">SaveAs</span>(<span class="hljs-title">stream</span>);
                    <span class="hljs-keyword">var</span> content <span class="hljs-operator">=</span> stream.ToArray();

                    <span class="hljs-keyword">var</span> fileName <span class="hljs-operator">=</span> <span class="hljs-string">"Maintenance Request Export "</span> <span class="hljs-operator">+</span> DateTime.Now.ToString(<span class="hljs-string">"dd-MM-yyyy"</span>) <span class="hljs-operator">+</span> <span class="hljs-string">" .xlsx"</span>; <span class="hljs-comment">//<span class="hljs-doctag">TODO:</span> see if this format can be changed in the app settings?</span>
                    await JSRuntime.InvokeAsync&lt;object<span class="hljs-operator">&gt;</span>(<span class="hljs-string">"saveAsFile"</span>, fileName, Convert.ToBase64String(content));
                } 
            }
        }
    }  
}
</code></pre><p>So the Javascript is add from a using statment so it can call the relevant javascript file from this line</p>
<pre><code><span class="hljs-keyword">using</span> <span class="hljs-title">Microsoft</span>.<span class="hljs-title">JSInterop</span>;
</code></pre><p>Then the IJSRuntime is injected into the class and constructor.</p>
<pre><code> <span class="hljs-keyword">private</span> <span class="hljs-keyword">readonly</span> IJSRuntime JSRuntime;

        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">MaintenanceRequestsExcel</span>(<span class="hljs-params">IJSRuntime jSRuntime</span>)</span>
        {
            JSRuntime = jSRuntime;
        }
</code></pre><p>The part of the method that creates the excel and download with the Javascript function is</p>
<pre><code><span class="hljs-keyword">using</span> (<span class="hljs-title"><span class="hljs-keyword">var</span></span> <span class="hljs-title">stream</span> <span class="hljs-operator">=</span> <span class="hljs-title"><span class="hljs-keyword">new</span></span> <span class="hljs-title">MemoryStream</span>())
{
       <span class="hljs-title">workbook</span>.<span class="hljs-title">SaveAs</span>(<span class="hljs-title">stream</span>);
        <span class="hljs-keyword">var</span> content <span class="hljs-operator">=</span> stream.ToArray();

        <span class="hljs-keyword">var</span> fileName <span class="hljs-operator">=</span> <span class="hljs-string">"Maintenance Request Export "</span> <span class="hljs-operator">+</span> DateTime.Now.ToString(<span class="hljs-string">"dd-MM-yyyy"</span>) <span class="hljs-operator">+</span> <span class="hljs-string">" .xlsx"</span>; <span class="hljs-comment">//<span class="hljs-doctag">TODO:</span> see if this format can be changed in the app settings?</span>
        await JSRuntime.InvokeAsync&lt;object<span class="hljs-operator">&gt;</span>(<span class="hljs-string">"saveAsFile"</span>, fileName, Convert.ToBase64String(content));
}
</code></pre><p>In the startup class in blazor the excel class is added as a service</p>
<pre><code>services.AddScoped&lt;MaintenanceRequestsExcel<span class="hljs-operator">&gt;</span>();
</code></pre><p>In the razor page file I call the excel class method to run the export function and download the file.  The method is tied to an onclick event of a button.</p>
<pre><code><span class="hljs-keyword">public</span> async Task ExportExcelFile()
 {
        await ExcelExport.ExportListToExcel(maintReqListViewModel.requests);
 }
</code></pre><p>Here is a quick video of it in action where it is exporting the table shown into an excel file.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/45fdh-PnnVI">https://youtu.be/45fdh-PnnVI</a></div>
]]></content:encoded></item><item><title><![CDATA[Custom CSS Checkbox]]></title><description><![CDATA[Creating this post so I can remember how to do this.
Picked this up from youtube from the blazor power hour:



This basically creates a check box which has a nice border and a tick mark in the top left which I have made look like:

This is done in a...]]></description><link>https://craigbrunton.social/custom-css-checkbox</link><guid isPermaLink="true">https://craigbrunton.social/custom-css-checkbox</guid><category><![CDATA[CSS]]></category><category><![CDATA[Blazor ]]></category><category><![CDATA[components]]></category><dc:creator><![CDATA[Craig Brunton]]></dc:creator><pubDate>Wed, 13 Oct 2021 17:33:14 GMT</pubDate><content:encoded><![CDATA[<p>Creating this post so I can remember how to do this.</p>
<p>Picked this up from youtube from the blazor power hour:</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/YKYlMg6daIQ"></iframe>


<p>This basically creates a check box which has a nice border and a tick mark in the top left which I have made look like:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1634145916217/PdKgEQp3i.png" alt="checkbox.PNG" /></p>
<p>This is done in a blazor project I am working on.</p>
<p>CSS:</p>
<pre><code><span class="hljs-selector-tag">body</span> {
    <span class="hljs-attribute">background</span>: <span class="hljs-number">#585c68</span>;
}

<span class="hljs-selector-class">.wrapper</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">780px</span>;
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">100px</span> auto <span class="hljs-number">0</span>;
}

    <span class="hljs-selector-class">.wrapper</span> <span class="hljs-selector-class">.title</span> {
        <span class="hljs-attribute">font-size</span>: <span class="hljs-number">24px</span>;
        <span class="hljs-attribute">color</span>: <span class="hljs-number">#fff</span>;
        <span class="hljs-attribute">font-weight</span>: <span class="hljs-number">700</span>;
        <span class="hljs-attribute">text-align</span>: center;
        <span class="hljs-attribute">margin-bottom</span>: <span class="hljs-number">50px</span>;
    }

<span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">flex-wrap</span>: wrap;
}

    <span class="hljs-selector-class">.container</span> <span class="hljs-selector-class">.option_item</span> {
        <span class="hljs-attribute">display</span>: block;
        <span class="hljs-attribute">position</span>: relative;
        <span class="hljs-attribute">width</span>: <span class="hljs-number">175px</span>;
        <span class="hljs-attribute">height</span>: <span class="hljs-number">175px</span>;
        <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
    }

        <span class="hljs-selector-class">.container</span> <span class="hljs-selector-class">.option_item</span> <span class="hljs-selector-class">.checkbox</span> {
            <span class="hljs-attribute">position</span>: absolute;
            <span class="hljs-attribute">top</span>: <span class="hljs-number">0</span>;
            <span class="hljs-attribute">left</span>: <span class="hljs-number">0</span>;
            <span class="hljs-attribute">z-index</span>: <span class="hljs-number">1</span>;
            <span class="hljs-attribute">opacity</span>: <span class="hljs-number">0</span>;
        }

<span class="hljs-selector-class">.option_item</span> <span class="hljs-selector-class">.option_inner</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">background</span>: <span class="hljs-number">#ebebf2</span>;
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">5px</span>;
    <span class="hljs-attribute">text-align</span>: center;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">58px</span> <span class="hljs-number">40px</span>;
    <span class="hljs-attribute">cursor</span>: pointer;
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#585c68</span>;
    <span class="hljs-attribute">display</span>: block;
    <span class="hljs-attribute">border</span>: <span class="hljs-number">5px</span> solid transparent;
    <span class="hljs-attribute">position</span>: relative;
}

    <span class="hljs-selector-class">.option_item</span> <span class="hljs-selector-class">.option_inner</span> <span class="hljs-selector-class">.icon</span> {
        <span class="hljs-attribute">margin-bottom</span>: <span class="hljs-number">10px</span>;
    }

        <span class="hljs-selector-class">.option_item</span> <span class="hljs-selector-class">.option_inner</span> <span class="hljs-selector-class">.icon</span> <span class="hljs-selector-class">.fab</span> {
            <span class="hljs-attribute">font-size</span>: <span class="hljs-number">32px</span>;
        }

    <span class="hljs-selector-class">.option_item</span> <span class="hljs-selector-class">.option_inner</span> <span class="hljs-selector-class">.name</span> {
        <span class="hljs-attribute">user-select</span>: none;
    }

<span class="hljs-selector-class">.option_item</span> <span class="hljs-selector-class">.checkbox</span><span class="hljs-selector-pseudo">:checked</span> ~ <span class="hljs-selector-class">.option_inner</span><span class="hljs-selector-class">.theme</span> {
    <span class="hljs-attribute">border-color</span>: <span class="hljs-number">#ff0000</span>;
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#ff0000</span>;
}

<span class="hljs-selector-class">.option_item</span> <span class="hljs-selector-class">.option_inner</span> <span class="hljs-selector-class">.tickmark</span> {
    <span class="hljs-attribute">position</span>: absolute;
    <span class="hljs-attribute">top</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">left</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">border</span>: <span class="hljs-number">20px</span> solid;
    <span class="hljs-attribute">border-color</span>: <span class="hljs-number">#000</span> transparent transparent <span class="hljs-number">#000</span>;
    <span class="hljs-attribute">display</span>: none;
}

    <span class="hljs-selector-class">.option_item</span> <span class="hljs-selector-class">.option_inner</span> <span class="hljs-selector-class">.tickmark</span><span class="hljs-selector-pseudo">:before</span> {
        <span class="hljs-attribute">content</span>: <span class="hljs-string">""</span>;
        <span class="hljs-attribute">position</span>: absolute;
        <span class="hljs-attribute">top</span>: -<span class="hljs-number">18px</span>;
        <span class="hljs-attribute">left</span>: -<span class="hljs-number">18px</span>;
        <span class="hljs-attribute">width</span>: <span class="hljs-number">15px</span>;
        <span class="hljs-attribute">height</span>: <span class="hljs-number">5px</span>;
        <span class="hljs-attribute">border</span>: <span class="hljs-number">3px</span> solid;
        <span class="hljs-attribute">border-color</span>: transparent transparent <span class="hljs-number">#fff</span> <span class="hljs-number">#fff</span>;
        <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">rotate</span>(-<span class="hljs-number">45deg</span>);
    }

<span class="hljs-selector-class">.option_item</span> <span class="hljs-selector-class">.checkbox</span><span class="hljs-selector-pseudo">:checked</span> ~ <span class="hljs-selector-class">.option_inner</span> <span class="hljs-selector-class">.tickmark</span> {
    <span class="hljs-attribute">display</span>: block;
}

<span class="hljs-selector-class">.option_item</span> <span class="hljs-selector-class">.option_inner</span><span class="hljs-selector-class">.theme</span> <span class="hljs-selector-class">.tickmark</span> {
    <span class="hljs-attribute">border-color</span>: <span class="hljs-number">#ff0000</span> transparent transparent <span class="hljs-number">#ff0000</span>;
}
</code></pre><p>Blazor Component Template:</p>
<pre><code>@typeparam TItem

<span class="hljs-operator">&lt;</span>div class<span class="hljs-operator">=</span><span class="hljs-string">"container"</span><span class="hljs-operator">&gt;</span>
    @foreach (<span class="hljs-keyword">var</span> item in Items)
    {
        <span class="hljs-keyword">var</span> Id <span class="hljs-operator">=</span> Guid.NewGuid();

        <span class="hljs-operator">&lt;</span>label <span class="hljs-keyword">for</span><span class="hljs-operator">=</span><span class="hljs-string">"@Id"</span> class<span class="hljs-operator">=</span><span class="hljs-string">"option_item"</span> <span class="hljs-operator">&gt;</span>
            <span class="hljs-operator">&lt;</span><span class="hljs-operator">!</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span> Check to see <span class="hljs-keyword">if</span> the checkbox needs to be checked or not <span class="hljs-keyword">from</span> the user data byt checking <span class="hljs-keyword">if</span> any of the items are already in the SelectedList <span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">&gt;</span>
            @<span class="hljs-keyword">if</span> (SelectedItems.Contains(item))
            {
                <span class="hljs-operator">&lt;</span>input id<span class="hljs-operator">=</span><span class="hljs-string">"@Id"</span> <span class="hljs-keyword">type</span><span class="hljs-operator">=</span><span class="hljs-string">"checkbox"</span> class<span class="hljs-operator">=</span><span class="hljs-string">"checkbox"</span> checked @onchange<span class="hljs-operator">=</span><span class="hljs-string">"_ =&gt; HandleChange(item)"</span> <span class="hljs-operator">/</span><span class="hljs-operator">&gt;</span>
                <span class="hljs-keyword">var</span> i <span class="hljs-operator">=</span> <span class="hljs-number">5</span>;
            }
            <span class="hljs-keyword">else</span>
            {
                <span class="hljs-operator">&lt;</span>input id<span class="hljs-operator">=</span><span class="hljs-string">"@Id"</span> <span class="hljs-keyword">type</span><span class="hljs-operator">=</span><span class="hljs-string">"checkbox"</span> class<span class="hljs-operator">=</span><span class="hljs-string">"checkbox"</span> @onchange<span class="hljs-operator">=</span><span class="hljs-string">"_ =&gt; HandleChange(item)"</span> <span class="hljs-operator">/</span><span class="hljs-operator">&gt;</span>
                <span class="hljs-keyword">var</span> ii <span class="hljs-operator">=</span> <span class="hljs-number">6</span>;
            }
            <span class="hljs-operator">&lt;</span>div class<span class="hljs-operator">=</span><span class="hljs-string">"option_inner theme"</span><span class="hljs-operator">&gt;</span>
                <span class="hljs-operator">&lt;</span>div class<span class="hljs-operator">=</span><span class="hljs-string">"tickmark"</span><span class="hljs-operator">&gt;</span><span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>
                <span class="hljs-operator">&lt;</span>div class<span class="hljs-operator">=</span><span class="hljs-string">"name"</span><span class="hljs-operator">&gt;</span>
                    @ItemTemplate(item)
                <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>
            <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>
        <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>label<span class="hljs-operator">&gt;</span>
    }
<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>



@code {
    [Parameter]
    <span class="hljs-keyword">public</span> IEnumerable<span class="hljs-operator">&lt;</span>TItem<span class="hljs-operator">&gt;</span> Items { get; set; }

    [Parameter]
    <span class="hljs-keyword">public</span> RenderFragment<span class="hljs-operator">&lt;</span>TItem<span class="hljs-operator">&gt;</span> ItemTemplate { get; set; }

    [Parameter]
    <span class="hljs-keyword">public</span> List<span class="hljs-operator">&lt;</span>TItem<span class="hljs-operator">&gt;</span> SelectedItems { get; set; } <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span>();

    [Parameter]
    <span class="hljs-keyword">public</span> EventCallback<span class="hljs-operator">&lt;</span>List<span class="hljs-operator">&lt;</span>TItem<span class="hljs-operator">&gt;</span><span class="hljs-operator">&gt;</span> SelectedItemsChanged { get; set; }

    void HandleChange(TItem item)
    {
        <span class="hljs-keyword">if</span> (SelectedItems.Contains(item))
        {
            SelectedItems.Remove(item);
        }
        <span class="hljs-keyword">else</span>
        {
            SelectedItems.Add(item);
        }

        SelectedItemsChanged.InvokeAsync(SelectedItems);
    }
}
</code></pre><p>The checking if an item already exists in the selected items list is done so that if it is then the box will be checked etc.</p>
<p>The implementation into a blazor page for my use is:</p>
<pre><code><span class="hljs-operator">&lt;</span>SquareCheckBox Items<span class="hljs-operator">=</span><span class="hljs-string">"maintReqInitation.Isolations"</span> Context<span class="hljs-operator">=</span><span class="hljs-string">"Isolation"</span> @bind<span class="hljs-operator">-</span>SelectedItems<span class="hljs-operator">=</span><span class="hljs-string">"maintReqInitation.IsolationsSelected"</span><span class="hljs-operator">&gt;</span>
                                    <span class="hljs-operator">&lt;</span>ItemTemplate<span class="hljs-operator">&gt;</span>
                                        <span class="hljs-operator">&lt;</span>div class<span class="hljs-operator">=</span><span class="hljs-string">"row"</span><span class="hljs-operator">&gt;</span>
                                            <span class="hljs-operator">&lt;</span>div class<span class="hljs-operator">=</span><span class="hljs-string">"col-lg-12"</span><span class="hljs-operator">&gt;</span>
                                                <span class="hljs-operator">&lt;</span>img src<span class="hljs-operator">=</span><span class="hljs-string">"@Isolation.ImageLocation"</span> alt<span class="hljs-operator">=</span><span class="hljs-string">"@Isolation.Name"</span> width<span class="hljs-operator">=</span><span class="hljs-string">"60"</span> height<span class="hljs-operator">=</span><span class="hljs-string">"60"</span> <span class="hljs-operator">/</span><span class="hljs-operator">&gt;</span>
                                            <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>
                                        <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>
                                        <span class="hljs-operator">&lt;</span>div class<span class="hljs-operator">=</span><span class="hljs-string">"row"</span><span class="hljs-operator">&gt;</span>
                                            <span class="hljs-operator">&lt;</span>div class<span class="hljs-operator">=</span><span class="hljs-string">"col-lg-12"</span><span class="hljs-operator">&gt;</span>
                                                @Isolation.Name
                                            <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>
                                        <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>
                                    <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>ItemTemplate<span class="hljs-operator">&gt;</span>
                                <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>SquareCheckBox<span class="hljs-operator">&gt;</span>
</code></pre><p>The ItemTemplate allows the content of the check box to be set how it is needed with a image, icon, text etc.</p>
]]></content:encoded></item></channel></rss>