|
|
|
@ -10,20 +10,20 @@ namespace ApiDePaul.Controllers
|
|
|
|
|
[Route("[controller]")]
|
|
|
|
|
public class ChampionController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
IDataManager donnees = new StubData();
|
|
|
|
|
|
|
|
|
|
private readonly ILogger<ChampionController> _logger;
|
|
|
|
|
|
|
|
|
|
public ChampionController(ILogger<ChampionController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<ActionResult<ChampionDto>> Get()
|
|
|
|
|
public async Task<ActionResult<ChampionDto>> GetChamps()
|
|
|
|
|
{
|
|
|
|
|
StubData stu = new StubData();
|
|
|
|
|
IEnumerable<Champion?> lcha = await donnees.ChampionsMgr.GetItems(0, donnees.ChampionsMgr.GetNbItems().Result);
|
|
|
|
|
|
|
|
|
|
IEnumerable<Champion?> lcha = await stu.ChampionsMgr.GetItems(0, stu.ChampionsMgr.GetNbItems().Result);
|
|
|
|
|
|
|
|
|
|
List<ChampionDto> champs = new List<ChampionDto>();
|
|
|
|
|
|
|
|
|
|
lcha.ToList().ForEach(c => champs.Add(c.ChampToDto()));
|
|
|
|
@ -31,94 +31,91 @@ namespace ApiDePaul.Controllers
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
|
public async Task<ActionResult<ChampionDto>> Get(int id)
|
|
|
|
|
public async Task<ActionResult<ChampionDto>> GetChampId(int id)
|
|
|
|
|
{
|
|
|
|
|
StubData stu = new StubData();
|
|
|
|
|
|
|
|
|
|
IEnumerable<Champion?> lcha = await donnees.ChampionsMgr.GetItems(id, 1);
|
|
|
|
|
|
|
|
|
|
IEnumerable<Champion?> lcha = await stu.ChampionsMgr.GetItems(id, 1);
|
|
|
|
|
|
|
|
|
|
if (id >= 0 && id < stu.ChampionsMgr.GetNbItems().Result)
|
|
|
|
|
if (id >= 0 && id < donnees.ChampionsMgr.GetNbItems().Result)
|
|
|
|
|
{
|
|
|
|
|
return Ok(lcha.First().ChampToDto());
|
|
|
|
|
}
|
|
|
|
|
return BadRequest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("{nom}")]
|
|
|
|
|
public async Task<ActionResult> Post(String nom)
|
|
|
|
|
|
|
|
|
|
[HttpGet("{id}/Skins")]
|
|
|
|
|
public async Task<ActionResult<SkinDto>> GetSkinsChamp(int id)
|
|
|
|
|
{
|
|
|
|
|
StubData stu = new StubData();
|
|
|
|
|
IEnumerable<Champion?> lcha = await donnees.ChampionsMgr.GetItems(id, 1);
|
|
|
|
|
|
|
|
|
|
Champion ca = new Champion(nom);
|
|
|
|
|
if (id >= 0 && id < donnees.ChampionsMgr.GetNbItems().Result)
|
|
|
|
|
{
|
|
|
|
|
Champion ca = lcha.First();
|
|
|
|
|
|
|
|
|
|
stu.ChampionsMgr.AddItem(ca);
|
|
|
|
|
IEnumerable<Skin?> lsk = await donnees.SkinsMgr.GetItemsByChampion(ca, 0, donnees.SkinsMgr.GetNbItemsByChampion(ca).Result);
|
|
|
|
|
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
List<SkinDto> skins = new List<SkinDto>();
|
|
|
|
|
lsk.ToList().ForEach(s => skins.Add(s.SkinToDto()));
|
|
|
|
|
|
|
|
|
|
// GET: ChampionController/Create
|
|
|
|
|
public ActionResult Create()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
return Ok(skins);
|
|
|
|
|
}
|
|
|
|
|
return BadRequest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: ChampionController/Create
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public ActionResult Create(IFormCollection collection)
|
|
|
|
|
|
|
|
|
|
[HttpPost("Ajouter/{nom}")]
|
|
|
|
|
public async Task<ActionResult> PostChampName(string nom)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
Champion ca = new Champion(nom);
|
|
|
|
|
|
|
|
|
|
await donnees.ChampionsMgr.AddItem(ca);
|
|
|
|
|
|
|
|
|
|
return CreatedAtAction(nameof(GetChampId), new { id = donnees.ChampionsMgr.GetNbItems().Result - 1 }, ca.ChampToDto());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: ChampionController/Edit/5
|
|
|
|
|
public ActionResult Edit(int id)
|
|
|
|
|
[HttpPost("Ajouter")]
|
|
|
|
|
public async Task<IActionResult> PostChamp([FromBody] ChampionDto c)
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
Champion ca = c.DtoToChamp();
|
|
|
|
|
await donnees.ChampionsMgr.AddItem(ca);
|
|
|
|
|
return CreatedAtAction(nameof(donnees.ChampionsMgr.GetItemsByName), new { Name = c.Name }, c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: ChampionController/Edit/5
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public ActionResult Edit(int id, IFormCollection collection)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpDelete("Supprimer/{id}")]
|
|
|
|
|
public async Task<IActionResult> DeleteChamp(int id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
IEnumerable<Champion?> lcha = await donnees.ChampionsMgr.GetItems(id, 1);
|
|
|
|
|
|
|
|
|
|
if (id >= 0 && id < donnees.ChampionsMgr.GetNbItems().Result)
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
Champion ca = lcha.First();
|
|
|
|
|
donnees.ChampionsMgr.DeleteItem(ca);
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
return BadRequest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: ChampionController/Delete/5
|
|
|
|
|
public ActionResult Delete(int id)
|
|
|
|
|
|
|
|
|
|
[HttpPut("Modifier/{nom}")]// CA C4EST PAS FINI
|
|
|
|
|
public async Task<ActionResult> PutChampName(string nom)
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
Champion ca = new Champion(nom);
|
|
|
|
|
|
|
|
|
|
await donnees.ChampionsMgr.AddItem(ca);
|
|
|
|
|
|
|
|
|
|
return CreatedAtAction(nameof(GetChampId), new { id = donnees.ChampionsMgr.GetNbItems().Result - 1 }, ca.ChampToDto());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: ChampionController/Delete/5
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public ActionResult Delete(int id, IFormCollection collection)
|
|
|
|
|
[HttpPut("Modifier")]
|
|
|
|
|
public async Task<IActionResult> PutChamp([FromBody] ChampionDto c, [FromBody] ChampionDto cNouv)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
Champion ca = c.DtoToChamp();
|
|
|
|
|
Champion caNouv = cNouv.DtoToChamp();
|
|
|
|
|
await donnees.ChampionsMgr.UpdateItem(ca,caNouv);
|
|
|
|
|
return CreatedAtAction(nameof(GetChampId), new { id = donnees.ChampionsMgr.GetItems(0,donnees.ChampionsMgr.GetNbItems().Result).Result.ToList().IndexOf(ca) }, ca);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|