I have created a code that displays a table with exchange rate data. Have I used loops and conditions (if else) in a good way?
@model IEnumerable<CurrencyResponse>
@{
ViewData["Title"] = "Index";
}
@foreach (var obj in Model)
{
<div>
<h5>Table: @obj.Table</h5>
<h5>Table number: @obj.No</h5>
<h5>Date of publication: @obj.EffectiveDate</h5>
@if (obj.Table == "C")
{
<h5>Quotation date: @obj.TradingDate</h5>
}
</div>
}
<table class="table table-bordered table-striped" style="width: 100%">
<thead>
<tr>
<th>
Currency
</th>
<th>
Code
</th>
@foreach (var obj in Model)
{
@if (obj.Table != "C")
{
<th>
Mid
</th>
}
else
{
<th>
Bid
</th>
<th>
Ask
</th>
}
}
</tr>
</thead>
<tbody>
@foreach (var obj in Model)
{
foreach (var element in obj.Rates)
{
<tr>
<td width="50%">
@element.Currency
</td>
<td width="50%">
@element.Code
</td>
@if (obj.Table != "C")
{
<td width="50%">
@element.Mid
</td>
}
else
{
<td width="50%">
@element.Bid
</td>
<td width="50%">
@element.Ask
</td>
}
</tr>
}
}
</tbody>
</table>
As you can see, I'm using 4 loops to display the data the right way. I am using conditions to add extra html. I wonder if what I'm doing is right. Can it be somehow more optimized? In the created div I use h5 tags to display information about the table (A, B or C) and information about the date of publication of the exchange rates.
xml structure - (tables A, B, C):
In case of ambiguity, I also attach all the code to the github: code