|
|
using API.Dto;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Newtonsoft.Json;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Net.Http;
|
|
|
using System.Net.Http.Headers;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace API.Controllers
|
|
|
{
|
|
|
public class ChampionController : ControllerBase
|
|
|
{
|
|
|
// GET: ChampionController
|
|
|
public ActionResult Index()
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
// GET: ChampionController/Details/5
|
|
|
public ActionResult Details(int id)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
// GET: ChampionController/Create
|
|
|
public ActionResult Create()
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
// POST: ChampionController/Create
|
|
|
[HttpPost]
|
|
|
[ValidateAntiForgeryToken]
|
|
|
public ActionResult Create(IFormCollection collection)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// GET: ChampionController/Edit/5
|
|
|
public ActionResult Edit(int id)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
// POST: ChampionController/Edit/5
|
|
|
[HttpPost]
|
|
|
[ValidateAntiForgeryToken]
|
|
|
public ActionResult Edit(int id, IFormCollection collection)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// GET: ChampionController/Delete/5
|
|
|
public ActionResult Delete(int id)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
// POST: ChampionController/Delete/5
|
|
|
[HttpPost]
|
|
|
[ValidateAntiForgeryToken]
|
|
|
public ActionResult Delete(int id, IFormCollection collection)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
[Route("{id}")]
|
|
|
public ActionResult<IEnumerable<ChampionDto>> GetById()
|
|
|
{
|
|
|
BadRequest("404");
|
|
|
|
|
|
return Ok(Enumerable.Range(1, 5).Select(index => new ChampionDto
|
|
|
{
|
|
|
Id = index,
|
|
|
Name = "Stark",
|
|
|
Bio = "Trop fort",
|
|
|
Icon = "nothing"
|
|
|
})
|
|
|
.ToArray());
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static async Task GetJsonData()
|
|
|
{
|
|
|
using var client = new HttpClient();
|
|
|
client.BaseAddress = new Uri("https://localhost:7175");
|
|
|
client.DefaultRequestHeaders.Accept.Clear();
|
|
|
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
|
|
|
|
|
HttpResponseMessage response = await client.GetAsync("/api/ChampionDto");
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
{
|
|
|
var responseBody = await response.Content.ReadAsStringAsync();
|
|
|
try
|
|
|
{
|
|
|
var songs = JsonConvert.DeserializeObject<List<ChampionDto>>(responseBody);
|
|
|
if (songs != null)
|
|
|
{
|
|
|
foreach (var song in songs)
|
|
|
{
|
|
|
Console.WriteLine($"Name: {song.Name},Year: {song.Yearreleased}");
|
|
|
}
|
|
|
}
|
|
|
Console.ReadLine();
|
|
|
}
|
|
|
catch (JsonReaderException)
|
|
|
{
|
|
|
Console.WriteLine("Something went wrong.");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
|
|
[HttpPost]
|
|
|
public async Task<IActionResult> post([FromBody] ChampionDto champion)
|
|
|
{
|
|
|
return CreatedAtAction(nameof(GetById), new { id = 1 },
|
|
|
await dataManager.ChampionMgr.AddItem(champion.ToModel()));
|
|
|
}
|
|
|
|
|
|
private readonly httpclient _client;
|
|
|
private const string Apichampion = "api/champion";
|
|
|
|
|
|
public championHttpManager(HttpClient client)
|
|
|
{
|
|
|
_client = client;
|
|
|
client.BaseAddress = new Uri("à chopper dans lauchSettings.json propriété du projet");
|
|
|
}
|
|
|
|
|
|
public async task<IEnumerable<ChampionDto>> getChampion()
|
|
|
{
|
|
|
var champions = await _client.getFromJsonAsync<IEnumerable<ChampionDto>>();
|
|
|
//var reponse = await _cleint.GetAscyn("api/champion") ;
|
|
|
return champions;
|
|
|
}
|
|
|
|
|
|
public async void addchampion(ChampionDto champion)
|
|
|
{
|
|
|
_clientLpostAsJsonAscync<Champion>(ApiChampion, champion);
|
|
|
}
|
|
|
*/
|
|
|
|
|
|
}
|
|
|
}
|