40 lines
1.6 KiB
C#
40 lines
1.6 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
using PokemonSleep.Web.Models;
|
|
using PokemonSleep.Web.Service.IService;
|
|
|
|
namespace PokemonSleep.Web.Controllers
|
|
{
|
|
public class PokemonController : Controller
|
|
{
|
|
|
|
private readonly IPokemonService _pokemonService;
|
|
private readonly IPokemonNatureService _natureService;
|
|
private readonly IPokemonSubskillService _subskillService;
|
|
public PokemonController(IPokemonService pokemonService, IPokemonNatureService natureService, IPokemonSubskillService subskillService)
|
|
{
|
|
_pokemonService = pokemonService;
|
|
_natureService = natureService;
|
|
_subskillService = subskillService;
|
|
}
|
|
public async Task<IActionResult> PokemonIndex()
|
|
{
|
|
PokemonSleepDto? list = new();
|
|
|
|
ResponseDto? presponse = await _pokemonService.GetAllPokemonAsync();
|
|
ResponseDto? nresponse = await _natureService.GetAllPokemonNaturesAsync();
|
|
ResponseDto? sresponse = await _subskillService.GetAllPokemonSubskillsAsync();
|
|
|
|
if (presponse != null && presponse.IsSuccess)
|
|
{
|
|
list.pokemonList = JsonConvert.DeserializeObject<List<PokemonDto>>(Convert.ToString(presponse.Result));
|
|
list.natureList = JsonConvert.DeserializeObject<List<PokemonNatureDto>>(Convert.ToString(nresponse.Result));
|
|
list.subskillList = JsonConvert.DeserializeObject<List<PokemonSubskillDto>>(Convert.ToString(sresponse.Result));
|
|
}
|
|
|
|
|
|
return View(list);
|
|
}
|
|
}
|
|
}
|