Skip to content

Commit

Permalink
Fix some broken model binding things and clean up various model thing…
Browse files Browse the repository at this point in the history
…s, still more to do
  • Loading branch information
adelikat committed Mar 24, 2024
1 parent d5bdf28 commit 4dbf7fd
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 38 deletions.
2 changes: 1 addition & 1 deletion TASVideos/Pages/Flags/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<th>Permission Restriction</th>
<th></th>
</tr>
@foreach (var flag in Model.Flags)
@foreach (var flag in Model.Flags.OrderBy(f => f.Token))
{
<tr>
<td>@flag.Name</td>
Expand Down
4 changes: 1 addition & 3 deletions TASVideos/Pages/Flags/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ public class IndexModel(IFlagService flagService) : BasePageModel

public async Task OnGet()
{
Flags = (await flagService.GetAll())
.OrderBy(t => t.Token)
.ToList();
Flags = await flagService.GetAll();
}
}
2 changes: 1 addition & 1 deletion TASVideos/Pages/Forum/Models/CategoryEditModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class CategoryEditModel

public string? Description { get; set; }

public IList<ForumEditModel> Forums { get; set; } = [];
public List<ForumEditModel> Forums { get; set; } = [];

public class ForumEditModel
{
Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Pages/Forum/Posts/Create.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class CreateModel(
[DisplayName("Watch Topic for Replies")]
public bool WatchTopic { get; set; }

public IEnumerable<MiniPostModel> PreviousPosts { get; set; } = [];
public List<MiniPostModel> PreviousPosts { get; set; } = [];

public AvatarUrls UserAvatars { get; set; } = new(null, null);

Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Pages/Forum/Posts/Edit.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class EditModel(
[BindProperty]
[DisplayName("Minor Edit")]
public bool MinorEdit { get; set; }
public IEnumerable<MiniPostModel> PreviousPosts { get; set; } = [];
public List<MiniPostModel> PreviousPosts { get; set; } = [];

public AvatarUrls UserAvatars { get; set; } = new(null, null);

Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Pages/Forum/Posts/User.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class UserModel(

public PageOf<UserPagePost> Posts { get; set; } = PageOf<UserPagePost>.Empty();

public IEnumerable<AwardAssignmentSummary> Awards { get; set; } = [];
public List<AwardAssignmentSummary> Awards { get; set; } = [];

public async Task<IActionResult> OnGet()
{
Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Pages/Forum/Subforum/Create.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class CreateModel(ApplicationDbContext db) : BasePageModel
[BindProperty]
public ForumEditModel Forum { get; set; } = new();

public IEnumerable<SelectListItem> AvailableCategories { get; set; } = [];
public List<SelectListItem> AvailableCategories { get; set; } = [];

public async Task<IActionResult> OnGet()
{
Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Pages/Forum/Subforum/Edit.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class EditModel(ApplicationDbContext db) : BasePageModel

public bool CanDelete { get; set; }

public IEnumerable<SelectListItem> AvailableCategories { get; set; } = [];
public List<SelectListItem> AvailableCategories { get; set; } = [];

public async Task<IActionResult> OnGet()
{
Expand Down
38 changes: 23 additions & 15 deletions TASVideos/Pages/Forum/Topics/Catalog.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class CatalogModel(ApplicationDbContext db) : BasePageModel
[FromRoute]
public int Id { get; set; }

public IEnumerable<SelectListItem> AvailableSystems { get; set; } = [];
public List<SelectListItem> AvailableSystems { get; set; } = [];

public IEnumerable<SelectListItem> AvailableGames { get; set; } = [];
public List<SelectListItem> AvailableGames { get; set; } = [];

[BindProperty]
public string Title { get; set; } = "";
Expand Down Expand Up @@ -86,22 +86,30 @@ public async Task<IActionResult> OnPost()

private async Task Initialize()
{
AvailableSystems = UiDefaults.DefaultEntry.Concat(await db.GameSystems
.OrderBy(s => s.Code)
.Select(s => new SelectListItem
{
Value = s.Id.ToString(),
Text = s.Code
})
.ToListAsync());
AvailableSystems =
[
.. UiDefaults.DefaultEntry,
.. await db.GameSystems
.OrderBy(s => s.Code)
.Select(s => new SelectListItem
{
Value = s.Id.ToString(),
Text = s.Code
})
.ToListAsync(),
];

if (SystemId.HasValue)
{
AvailableGames = UiDefaults.DefaultEntry.Concat(await db.Games
.ForSystem(SystemId.Value)
.OrderBy(g => g.DisplayName)
.ToDropDown()
.ToListAsync());
AvailableGames =
[
.. UiDefaults.DefaultEntry,
.. await db.Games
.ForSystem(SystemId.Value)
.OrderBy(g => g.DisplayName)
.ToDropDown()
.ToListAsync(),
];
}
}
}
6 changes: 3 additions & 3 deletions TASVideos/Pages/Forum/Topics/Merge.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public class MergeModel(
[BindProperty]
public MergeTopicModel Topic { get; set; } = new();

public IEnumerable<SelectListItem> AvailableForums { get; set; } = [];
public List<SelectListItem> AvailableForums { get; set; } = [];

public IEnumerable<SelectListItem> AvailableTopics { get; set; } = [];
public List<SelectListItem> AvailableTopics { get; set; } = [];

private bool CanSeeRestricted => User.Has(PermissionTo.SeeRestrictedForums);

Expand Down Expand Up @@ -135,7 +135,7 @@ private async Task PopulateAvailableForums()
})
.ToListAsync();

AvailableTopics = UiDefaults.DefaultEntry.Concat(await GetTopicsForForum(Topic.ForumId));
AvailableTopics = [.. UiDefaults.DefaultEntry, .. await GetTopicsForForum(Topic.ForumId)];
}

private async Task<IEnumerable<SelectListItem>> GetTopicsForForum(int forumId)
Expand Down
6 changes: 3 additions & 3 deletions TASVideos/Pages/Forum/Topics/Models/MoveTopicModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace TASVideos.Pages.Forum.Topics.Models;
public class MoveTopicModel
{
[Display(Name = "New Forum")]
public int ForumId { get; set; }
public int ForumId { get; init; }

[Display(Name = "Topic")]
public string TopicTitle { get; set; } = "";
public string TopicTitle { get; init; } = "";

[Display(Name = "Current Forum")]
public string ForumName { get; set; } = "";
public string ForumName { get; init; } = "";
}
2 changes: 1 addition & 1 deletion TASVideos/Pages/Forum/Topics/Models/PollCreateModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class PollCreateModel
public bool MultiSelect { get; set; }

[Display(Name = "Options")]
public IList<string> PollOptions { get; set; } = ["", ""];
public List<string> PollOptions { get; set; } = ["", ""];

public bool IsValid =>
!string.IsNullOrWhiteSpace(Question)
Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Pages/Forum/Topics/Models/PollResultModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class PollResultModel

public string Question { get; set; } = "";

public IEnumerable<VoteResult> Votes { get; set; } = [];
public List<VoteResult> Votes { get; set; } = [];

public class VoteResult
{
Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Pages/Forum/Topics/Models/SplitTopicModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SplitTopicModel
public int ForumId { get; set; }
public string ForumName { get; set; } = "";

public IList<Post> Posts { get; set; } = [];
public List<Post> Posts { get; set; } = [];

public class Post
{
Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Pages/Forum/Topics/Move.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class MoveModel(
[BindProperty]
public MoveTopicModel Topic { get; set; } = new();

public IEnumerable<SelectListItem> AvailableForums { get; set; } = [];
public List<SelectListItem> AvailableForums { get; set; } = [];

public bool CanSeeRestricted => User.Has(PermissionTo.SeeRestrictedForums);

Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Pages/Forum/Topics/Split.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class SplitModel(
[BindProperty]
public SplitTopicModel Topic { get; set; } = new();

public IEnumerable<SelectListItem> AvailableForums { get; set; } = [];
public List<SelectListItem> AvailableForums { get; set; } = [];

private bool CanSeeRestricted => User.Has(PermissionTo.SeeRestrictedForums);

Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Pages/GameGroups/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class IndexModel(ApplicationDbContext db) : BasePageModel

public int ParsedId => int.TryParse(Id, out var id) ? id : -1;

public IEnumerable<GameListEntry> Games { get; set; } = [];
public List<GameListEntry> Games { get; set; } = [];

public string Name { get; set; } = "";
public string? Description { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Pages/GameGroups/List.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace TASVideos.Pages.GameGroups;
[AllowAnonymous]
public class ListModel(ApplicationDbContext db) : BasePageModel
{
public IEnumerable<GroupListEntry> GameGroups { get; set; } = [];
public List<GroupListEntry> GameGroups { get; set; } = [];

public async Task OnGet()
{
Expand Down

0 comments on commit 4dbf7fd

Please sign in to comment.