Files
game-ideas/src/GameIdeas/Client/GameIdeas.BlazorApp/Helpers/GameHelper.cs
Egamorf b3212c5e0d
All checks were successful
Game Ideas build for PR / build_blazor_app (pull_request) Successful in 40s
Authorize API
2025-04-21 01:52:01 +02:00

55 lines
1.5 KiB
C#

using GameIdeas.Shared.Dto;
using Microsoft.AspNetCore.Components.Authorization;
using System.Security.Claims;
namespace GameIdeas.BlazorApp.Helpers;
public static class GameHelper
{
public static void WriteTrackingDto(GameDetailDto game, AuthenticationState authState)
{
if (authState == null)
{
throw new ArgumentNullException(nameof(authState), "Authentication state missing");
}
var userId = authState.User.FindFirstValue(ClaimTypes.Sid);
if (userId == null)
{
throw new ArgumentNullException(nameof(authState), "user state missing");
}
game.CreationUserId = userId;
game.CreationDate = DateTime.Now;
}
public static string GetInterestColor(int interest, int maxInterest)
{
int firstTier = (int)Math.Floor(0.33 * maxInterest);
int secondTier = (int)Math.Ceiling(0.66 * maxInterest);
return interest switch
{
int x when x <= firstTier => "--red",
int x when x >= secondTier => "--green",
_ => "--yellow",
};
}
public static string GetFormatedStorageSpace(double? storageValue)
{
if (storageValue == null)
{
return string.Empty;
}
return storageValue switch
{
>= 1000000 => $"{storageValue / 1000000:f1} To",
>= 1000 => $"{storageValue / 1000:f1} Go",
_ => $"{storageValue:f1} Mo"
};
}
}