Skip to content

Commit

Permalink
Simplify some awards editor view model stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
adelikat committed Mar 24, 2024
1 parent b20a9ec commit d5bdf28
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 31 deletions.
5 changes: 1 addition & 4 deletions TASVideos/Pages/AwardsEditor/CreateCategory.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ namespace TASVideos.Pages.AwardsEditor;
[RequirePermission(PermissionTo.CreateAwards)]
public class CreateCategoryModel(IAwards awards, IMediaFileUploader mediaFileUploader) : BasePageModel
{
private static readonly IEnumerable<AwardType> AwardTypes = Enum
public IEnumerable<SelectListItem> AvailableAwardTypes { get; set; } = Enum
.GetValues(typeof(AwardType))
.Cast<AwardType>()
.ToList();

public IEnumerable<SelectListItem> AvailableAwardTypes { get; set; } = AwardTypes
.Select(a => new SelectListItem
{
Text = a.ToString(),
Expand Down
21 changes: 10 additions & 11 deletions TASVideos/Pages/AwardsEditor/ListCategories.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,25 @@
using TASVideos.Data;
using TASVideos.Data.Entity;
using TASVideos.Data.Entity.Awards;
using TASVideos.Pages.AwardsEditor.Models;

namespace TASVideos.Pages.AwardsEditor;

[RequirePermission(PermissionTo.CreateAwards)]
public class ListCategoryModel(ApplicationDbContext db, IMediaFileUploader mediaFileUploader)
: BasePageModel
{
public IEnumerable<AwardCategoryEntry> Categories { get; set; } = [];
public List<AwardCategoryEntry> Categories { get; set; } = [];

public async Task<IActionResult> OnGet()
{
Categories = await db.Awards
.Select(a => new AwardCategoryEntry
{
Id = a.Id,
Type = a.Type,
ShortName = a.ShortName,
Description = a.Description,
InUse = db.PublicationAwards.Any(pa => pa.AwardId == a.Id)
|| db.UserAwards.Any(ua => ua.AwardId == a.Id)
})
.Select(a => new AwardCategoryEntry(
a.Id,
a.Type,
a.ShortName,
a.Description,
db.PublicationAwards.Any(pa => pa.AwardId == a.Id)
|| db.UserAwards.Any(ua => ua.AwardId == a.Id)))
.ToListAsync();
return Page();
}
Expand Down Expand Up @@ -57,4 +54,6 @@ public async Task<IActionResult> OnPostDelete(int id)

return BasePageRedirect("ListCategories");
}

public record AwardCategoryEntry(int Id, AwardType Type, string ShortName, string Description, bool InUse);
}
15 changes: 0 additions & 15 deletions TASVideos/Pages/AwardsEditor/Models/AwardCategoryEntry.cs

This file was deleted.

2 changes: 1 addition & 1 deletion TASVideos/Pages/AwardsEditor/UploadImage.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class UploadImageModel(IMediaFileUploader mediaFileUploader, IAwards awar
[FromRoute]
public int Year { get; set; }

public IReadOnlyCollection<SelectListItem> AvailableAwardCategories { get; set; } = [];
public List<SelectListItem> AvailableAwardCategories { get; set; } = [];

[BindProperty]
public UploadImageViewModel ImageToUpload { get; set; } = new();
Expand Down

0 comments on commit d5bdf28

Please sign in to comment.