|
|
|
@ -15,7 +15,7 @@ namespace Web_Api.Controllers
|
|
|
|
|
public class ChampionsController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private StubData.ChampionsManager ChampionsManager { get; set; } = new StubData.ChampionsManager(new StubData());
|
|
|
|
|
private ChampionsManager ChampionsManager { get; set; } = new StubData.ChampionsManager(new StubData());
|
|
|
|
|
|
|
|
|
|
private readonly LolContext _context;
|
|
|
|
|
|
|
|
|
@ -47,8 +47,7 @@ namespace Web_Api.Controllers
|
|
|
|
|
var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);
|
|
|
|
|
if (championSelected.Count() == 0)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Aucun champion ne correspond au nom { " + name + " } !");
|
|
|
|
|
throw new Exception("Aucun champion ne correspond au nom { " + name + " } !");
|
|
|
|
|
return NotFound("Aucun champion ne correspond au nom { " + name + " } !");
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine("Le champion { " + name + " } existe");
|
|
|
|
|
return Ok(championSelected.Select(champion => champion?.toDTO()));
|
|
|
|
@ -63,8 +62,7 @@ namespace Web_Api.Controllers
|
|
|
|
|
{
|
|
|
|
|
champion.Bio = "Aucune bio";
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine("Le champion { " + champion.Name + " } avec pour bio { " + champion.Bio + " } a bien été ajouté");
|
|
|
|
|
return Ok();
|
|
|
|
|
return Ok("Le champion { " + champion.Name + " } avec pour bio { " + champion.Bio + " } a bien été ajouté");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPut("UPDATE")]
|
|
|
|
@ -74,8 +72,7 @@ namespace Web_Api.Controllers
|
|
|
|
|
var existingChampion = championSelected.FirstOrDefault();
|
|
|
|
|
if (existingChampion == null)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Le champion { " + name + " } n'existe pas !");
|
|
|
|
|
return NotFound();
|
|
|
|
|
return NotFound("Le champion { " + name + " } n'existe pas !");
|
|
|
|
|
}
|
|
|
|
|
var updatedChampion = champion.toModel();
|
|
|
|
|
await ChampionsManager.UpdateItem(existingChampion, updatedChampion);
|
|
|
|
@ -83,8 +80,7 @@ namespace Web_Api.Controllers
|
|
|
|
|
{
|
|
|
|
|
updatedChampion.Bio = "Aucune bio";
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine("Le champion { " + name + " } a été modifié en { " + updatedChampion.Name + " } avec pour bio { " + updatedChampion.Bio + " }");
|
|
|
|
|
return Ok();
|
|
|
|
|
return Ok("Le champion { " + name + " } a été modifié en { " + updatedChampion.Name + " } avec pour bio { " + updatedChampion.Bio + " }");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpDelete("DELETE")]
|
|
|
|
@ -93,91 +89,9 @@ namespace Web_Api.Controllers
|
|
|
|
|
var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);
|
|
|
|
|
if(!await ChampionsManager.DeleteItem(championSelected.FirstOrDefault()))
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("champion { " + name + " } non trouvé !");
|
|
|
|
|
return NotFound();
|
|
|
|
|
return NotFound("champion { " + name + " } non trouvé !");
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine("champion { " + name + " } supprimé");
|
|
|
|
|
return Ok();
|
|
|
|
|
return Ok("champion { " + name + " } supprimé");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*[HttpGet(Name = "GetChampionsById")]
|
|
|
|
|
public async Task<IActionResult> GetById()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
/*// GET: ChampionsController
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: ChampionsController/Details/5
|
|
|
|
|
public ActionResult Details(int id)
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: ChampionsController/Create
|
|
|
|
|
public ActionResult Create()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: ChampionsController/Create
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public ActionResult Create(IFormCollection collection)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: ChampionsController/Edit/5
|
|
|
|
|
public ActionResult Edit(int id)
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: ChampionsController/Edit/5
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public ActionResult Edit(int id, IFormCollection collection)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: ChampionsController/Delete/5
|
|
|
|
|
public ActionResult Delete(int id)
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: ChampionsController/Delete/5
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public ActionResult Delete(int id, IFormCollection collection)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|