|
|
|
@ -87,11 +87,20 @@ namespace ApiDePaul.Controllers
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("Ajouter")]
|
|
|
|
|
public async Task<IActionResult> PostChamp([FromBody] ChampionDto c)
|
|
|
|
|
public async Task<ActionResult> PostChamp([FromBody] ChampionDto c)
|
|
|
|
|
{
|
|
|
|
|
Champion ca = c.DtoToChamp();
|
|
|
|
|
await donnees.ChampionsMgr.AddItem(ca);
|
|
|
|
|
return CreatedAtAction(nameof(donnees.ChampionsMgr.GetItemsByName), new { Name = c.Name }, c);
|
|
|
|
|
return Ok(await donnees.ChampionsMgr.AddItem(ca));
|
|
|
|
|
//return CreatedAtAction(nameof(donnees.ChampionsMgr.GetItemsByName), new { Name = c.Name }, c);
|
|
|
|
|
}
|
|
|
|
|
[HttpPost("AjouterPlus")]
|
|
|
|
|
public async Task<ActionResult> PostChamps([FromBody] List<ChampionDto> lc)
|
|
|
|
|
{
|
|
|
|
|
foreach(ChampionDto c in lc)
|
|
|
|
|
{
|
|
|
|
|
await donnees.ChampionsMgr.AddItem(c.DtoToChamp());
|
|
|
|
|
}
|
|
|
|
|
return Ok(lc.Count());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -105,21 +114,31 @@ namespace ApiDePaul.Controllers
|
|
|
|
|
if (id >= 0 && id < donnees.ChampionsMgr.GetNbItems().Result)
|
|
|
|
|
{
|
|
|
|
|
Champion ca = lcha.First();
|
|
|
|
|
donnees.ChampionsMgr.DeleteItem(ca);
|
|
|
|
|
return Ok();
|
|
|
|
|
return Ok(donnees.ChampionsMgr.DeleteItem(ca));
|
|
|
|
|
}
|
|
|
|
|
return BadRequest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPut("Modifier/{nom}")]// CA C4EST PAS FINI
|
|
|
|
|
public async Task<ActionResult> PutChampName(string nom)
|
|
|
|
|
{
|
|
|
|
|
Champion ca = new Champion(nom);
|
|
|
|
|
|
|
|
|
|
await donnees.ChampionsMgr.AddItem(ca);
|
|
|
|
|
|
|
|
|
|
return CreatedAtAction(nameof(GetChampId), new { id = donnees.ChampionsMgr.GetNbItems().Result - 1 }, ca.ChampToDto());
|
|
|
|
|
[HttpPut("{id}/Modifier")]
|
|
|
|
|
public async Task<ActionResult> PutChamp(int id, [FromBody] ChampionDto c)
|
|
|
|
|
{
|
|
|
|
|
IEnumerable<Champion?> oldChamp = await donnees.ChampionsMgr.GetItems(id, 1);
|
|
|
|
|
Champion champion1 = oldChamp.First();
|
|
|
|
|
Champion champion2 = c.DtoToChamp();
|
|
|
|
|
return Ok(await donnees.ChampionsMgr.UpdateItem(champion1, champion2));
|
|
|
|
|
}
|
|
|
|
|
[HttpPut("{id}/ModifierPlus")]
|
|
|
|
|
public async Task<ActionResult> PutChamps(int id, [FromBody] List<ChampionDto> lc)
|
|
|
|
|
{
|
|
|
|
|
IEnumerable<Champion?> oldChamp = await donnees.ChampionsMgr.GetItems(id, lc.Count());
|
|
|
|
|
for(int i=id;i<lc.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
Champion champion1 = oldChamp.Skip(i).Take(1).First();
|
|
|
|
|
Champion champion2 = lc[i].DtoToChamp();
|
|
|
|
|
await donnees.ChampionsMgr.UpdateItem(champion1, champion2);
|
|
|
|
|
}
|
|
|
|
|
return Ok(lc.Count());
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
[HttpPut("Modifier")]
|
|
|
|
|