Skip to content

Commit a54ec7e

Browse files
feat: Implement GameTypeExtensions for display name conversion and update PermissionsReport to use new method
1 parent 6de430e commit a54ec7e

3 files changed

Lines changed: 24 additions & 17 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using XtremeIdiots.Portal.Repository.Abstractions.Constants.V1;
3+
4+
namespace XtremeIdiots.Portal.Web.Extensions;
5+
6+
public static class GameTypeExtensions
7+
{
8+
public static string ToDisplayName(this GameType gameType)
9+
{
10+
var memberInfo = typeof(GameType).GetMember(gameType.ToString());
11+
if (memberInfo.Length > 0)
12+
{
13+
var displayAttr = memberInfo[0]
14+
.GetCustomAttributes(typeof(DisplayAttribute), false)
15+
.FirstOrDefault() as DisplayAttribute;
16+
if (displayAttr?.Name is not null)
17+
return displayAttr.Name;
18+
}
19+
return gameType.ToString();
20+
}
21+
}

src/XtremeIdiots.Portal.Web/Services/NotificationDispatcher.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using XtremeIdiots.Portal.Repository.Abstractions.Constants.V1;
33
using XtremeIdiots.Portal.Repository.Abstractions.Models.V1.Notifications;
44
using XtremeIdiots.Portal.Repository.Api.Client.V1;
5+
using XtremeIdiots.Portal.Web.Extensions;
56

67
namespace XtremeIdiots.Portal.Web.Services;
78

@@ -176,19 +177,4 @@ private static string BuildMetadata(AdminActionNotificationContext context)
176177
}
177178
}
178179

179-
internal static class GameTypeExtensions
180-
{
181-
public static string ToDisplayName(this GameType gameType)
182-
{
183-
var memberInfo = typeof(GameType).GetMember(gameType.ToString());
184-
if (memberInfo.Length > 0)
185-
{
186-
var displayAttr = memberInfo[0]
187-
.GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.DisplayAttribute), false)
188-
.FirstOrDefault() as System.ComponentModel.DataAnnotations.DisplayAttribute;
189-
if (displayAttr?.Name is not null)
190-
return displayAttr.Name;
191-
}
192-
return gameType.ToString();
193-
}
194-
}
180+

src/XtremeIdiots.Portal.Web/Views/User/PermissionsReport.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<option value="">All Games</option>
1111
@foreach (var gt in new[] { GameType.CallOfDuty2, GameType.CallOfDuty4, GameType.CallOfDuty5, GameType.Insurgency })
1212
{
13-
<option value="@gt">@gt.DisplayName()</option>
13+
<option value="@gt">@gt.ToDisplayName()</option>
1414
}
1515
</select>
1616
</div>

0 commit comments

Comments
 (0)