Skip to content

Commit

Permalink
Fix-up errors when viewing flight details if there are no custom flig…
Browse files Browse the repository at this point in the history
…ht properties
  • Loading branch information
davewalker5 committed Mar 8, 2024
1 parent 4b107f3 commit a838b09
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
31 changes: 17 additions & 14 deletions src/DroneFlightLog.Mvc/Controllers/FlightDetailsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,23 @@ public async Task<IActionResult> Index(FlightDetailsViewModel model)
model.UpdatePropertiesFromBoundValues();

// Save newly added property values
for (int i = 0; i < model.Properties.Count; i++)
{
FlightPropertyValue value = model.Properties[i];
if (value.IsNewPropertyValue)
{
model.Properties[i] = await AddNewPropertyValueAsync(model.Id, model.Properties[i]);
}
else if (value.Id > 0)
{
model.Properties[i] = await _properties.UpdateFlightPropertyValueAsync(
value.Id,
value.NumberValue,
value.StringValue,
value.DateValue);
if (model.Properties?.Count > 0)
{
for (int i = 0; i < model.Properties.Count; i++)
{
FlightPropertyValue value = model.Properties[i];
if (value.IsNewPropertyValue)
{
model.Properties[i] = await AddNewPropertyValueAsync(model.Id, model.Properties[i]);
}
else if (value.Id > 0)
{
model.Properties[i] = await _properties.UpdateFlightPropertyValueAsync(
value.Id,
value.NumberValue,
value.StringValue,
value.DateValue);
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/DroneFlightLog.Mvc/Models/FlightDetailsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public void MergeProperties(List<FlightProperty> availableProperties)
}
else
{
Properties = availableProperties.Select(m => new FlightPropertyValue { Property = m }).ToList();
Properties = availableProperties?.Select(m => new FlightPropertyValue { Property = m }).ToList();
}

// Sort the properties by name
Properties = Properties.OrderBy(p => p.Property.Name).ToList();
Properties = Properties?.OrderBy(p => p.Property.Name).ToList();
}

/// <summary>
Expand Down
31 changes: 17 additions & 14 deletions src/DroneFlightLog.Mvc/Views/FlightDetails/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,26 @@
</p>
<hr />

@for (int i = 0; i < (Model.Properties.Count / Model.PropertiesPerRow) + 1; i++)
@if (Model.Properties != null)
{
<div class="row">
@for (int j = 0; j < Model.PropertiesPerRow; j++)
{
int index = i * Model.PropertiesPerRow + j;
if (index < Model.Properties.Count)
for (int i = 0; i < (Model.Properties.Count / Model.PropertiesPerRow) + 1; i++)
{
<div class="row">
@for (int j = 0; j < Model.PropertiesPerRow; j++)
{
@await Html.PartialAsync("../Shared/FlightPropertyValue", Model.Properties[index]);
int index = i * Model.PropertiesPerRow + j;
if (index < Model.Properties.Count)
{
@await Html.PartialAsync("../Shared/FlightPropertyValue", Model.Properties[index]);
}
else
{
<div class="col"></div>
}
}
else
{
<div class="col"></div>
}
}
</div>
<br />
</div>
<br />
}
}

<hr />
Expand Down

0 comments on commit a838b09

Please sign in to comment.