Refactor enum handling in MemoryCache and HistoryController

Updated `GetEnumAsDictionary<TEnum>` in `MemoryCacheExtensions.cs` to use a loop for populating a dictionary of enum values, removing LINQ for simplicity.

Modified `HistoryController.cs` to adjust method signatures for `GetReferenceTypes` and `GetEnvelopeStatus`, allowing optional parameters for better conditional responses. Added necessary using directives.
This commit is contained in:
Developer 02
2025-05-08 12:00:48 +02:00
parent 3035ec7e9c
commit 7fefc68061
2 changed files with 16 additions and 25 deletions

View File

@@ -1,4 +1,5 @@
using Microsoft.Extensions.Caching.Memory;
using System;
namespace EnvelopeGenerator.Extensions;
@@ -7,15 +8,13 @@ public static class MemoryCacheExtensions
public static IDictionary<string, int> GetEnumAsDictionary<TEnum>(this IMemoryCache memoryCache)
where TEnum : Enum
{
var referenceTypes = Enum.GetValues(typeof(TEnum))
.Cast<TEnum>()
.ToDictionary(rt =>
{
var key = rt.ToString();
var keyAsCamelCase = char.ToLowerInvariant(key[0]) + key[1..];
return keyAsCamelCase;
}, rt => Convert.ToInt32(rt));
var dict = new Dictionary<string, int>();
return referenceTypes;
foreach (TEnum role in Enum.GetValues(typeof(TEnum)))
{
dict[role.ToString()] = Convert.ToInt32(role);
}
return dict;
}
}