Ciao,
ho un problema con un enum. Se dalla GUI cambio il valore nel controller non mi arriva.
Model
public enum GameProviderLoad
{
AA,
BB,
CC
}
public class GamesListViewModel
{
public GameProviderLoad GameProviderLoad { get; set; }
public IEnumerable<SelectListItem> GameProviderList
{
get
{
var priorityType = typeof(GameProviderLoad);
var priorityValues = Enum.GetValues(priorityType).Cast<GameProviderLoad>();
var converter = TypeDescriptor.GetConverter(priorityType);
return
from priorityValue in priorityValues
select new SelectListItem
{
Text = converter.ConvertToString(priorityValue),
Value = priorityValue.ToString(),
};
}
}
}
Controller
[HttpGet("administrator/games/fetch")]
public async Task<IActionResult> FetchGames(GamesListViewModel model)
{
switch (model.GameProviderLoad)
{
case GameProviderLoad.AA:
await AAService.FetchAndUpdateGamesAsync();
break;
case GameProviderLoad.BB:
await BBService.FetchAndUpdateGamesAsync();
break;
case GameProviderLoad.CC:
await CCntegrationService.PragmaticLobby.FetchAndUpdateGamesAsync();
break;
}
return View("~/Views/Administrator/Games/GamesList.cshtml", new GamesListViewModel { Games = await Game.GetAllAsync() });
}
View
<div class="page-header">
<h2>@_s("Stored Games")</h2>
<div class="text-center pt-4">
@Html.DropDownListFor(m => m.GameProviderLoad, Model.GameProviderList, @_s("Please select the provider"))
</div>
<div class="text-center pt-4">
<a class="btn btn-primary" href="/administrator/games/fetch">
<em class="fas fa-cloud-download-alt"></em>
@_s("Fetch Games")
</a>
<button class="btn btn-success" type="submit" form="game-order-form">@_s("Save Order")</button>
</div>
</div>
GameProviderLoad rimane fisso a AA.
Grazie per il prezioso aiuto.
Simone