Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions website/MyWebApp/Controllers/AdminBlockTemplateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ private async Task LoadPagesAsync()
{
ViewBag.Pages = await _db.Pages.AsNoTracking().OrderBy(p => p.Slug).ToListAsync();
ViewBag.Roles = await _db.Roles.AsNoTracking().OrderBy(r => r.Name).ToListAsync();
ViewBag.Zones = await _db.PageSections.AsNoTracking()
.Select(s => s.Zone)
.Distinct()
.OrderBy(z => z)
.ToListAsync();
}

public async Task<IActionResult> Index()
Expand Down Expand Up @@ -202,11 +207,11 @@ public async Task<IActionResult> AddToPage(int id, List<int> pageIds, string zon
}
foreach (var pageId in pageIds)
{
var sort = await _db.PageSections
var maxSort = await _db.PageSections
.Where(s => s.PageId == pageId && s.Zone == zone)
.Select(s => s.SortOrder)
.DefaultIfEmpty(-1)
.MaxAsync() + 1;
.Select(s => (int?)s.SortOrder)
.MaxAsync();
var sort = (maxSort ?? -1) + 1;
var section = new PageSection
{
PageId = pageId,
Expand Down Expand Up @@ -235,11 +240,11 @@ private async Task AddSectionsAsync(BlockTemplate template, List<int>? pageIds,
}
foreach (var pageId in pageIds)
{
var sort = await _db.PageSections
var maxSort = await _db.PageSections
.Where(s => s.PageId == pageId && s.Zone == zone)
.Select(s => s.SortOrder)
.DefaultIfEmpty(-1)
.MaxAsync() + 1;
.Select(s => (int?)s.SortOrder)
.MaxAsync();
var sort = (maxSort ?? -1) + 1;
var section = new PageSection
{
PageId = pageId,
Expand Down
7 changes: 6 additions & 1 deletion website/MyWebApp/Views/AdminBlockTemplate/AddToPage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
</div>
<div>
<label>Zone</label>
<input type="text" name="zone" />
<select id="zone-select" name="zone">
@foreach (var z in ViewBag.Zones as List<string>)
{
<option value="@z">@z</option>
}
</select>
</div>
<div>
<label>Role</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<input type="text" id="page-display" readonly />
<select id="page-select" name="pageIds" multiple size="5">
<option value="0">All Pages</option>
@foreach (var p in ViewBag.Pages as List<Page>)

Check warning on line 9 in website/MyWebApp/Views/AdminBlockTemplate/_PageAssignment.cshtml

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 9 in website/MyWebApp/Views/AdminBlockTemplate/_PageAssignment.cshtml

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
{
<option value="@p.Id">@p.Slug</option>
}
Expand All @@ -14,7 +14,12 @@
</div>
<div>
<label>Zone</label>
<input type="text" name="zone" />
<select id="zone-select" name="zone">
@foreach (var z in ViewBag.Zones as List<string>)
{
<option value="@z">@z</option>
}
</select>
</div>
<div>
<label>Role</label>
Expand Down
Loading