|
|
|
@ -1,83 +1,98 @@
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using DataBase.DataManager;
|
|
|
|
|
using DataBase.Entity;
|
|
|
|
|
using DTO;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
|
|
|
|
namespace ApiLeapHit.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class PlayerController : Controller
|
|
|
|
|
public class PlayerController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
// GET: PlayerController
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
private readonly DbDataManager _dataManager;
|
|
|
|
|
|
|
|
|
|
// GET: PlayerController/Details/5
|
|
|
|
|
public ActionResult Details(int id)
|
|
|
|
|
public PlayerController(DbDataManager dataManager)
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
_dataManager = dataManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: PlayerController/Create
|
|
|
|
|
public ActionResult Create()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: PlayerController/Create
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public ActionResult Create(IFormCollection collection)
|
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
|
public async Task<ActionResult<DTOPlayer>> GetPlayer(int id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
var player = await _dataManager.GetPlayer(id);
|
|
|
|
|
if (player == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var dtoPlayer = new DTOPlayer
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
playerId = player.playerId,
|
|
|
|
|
name = player.name,
|
|
|
|
|
nbBallTouchTotal = player.nbBallTouchTotal,
|
|
|
|
|
timePlayed = player.timePlayed,
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
return Ok(dtoPlayer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: PlayerController/Edit/5
|
|
|
|
|
public ActionResult Edit(int id)
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<ActionResult> AddPlayer([FromBody] DTOPlayer dtoPlayer)
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
|
|
|
|
|
var player = new Player
|
|
|
|
|
{
|
|
|
|
|
playerId = dtoPlayer.playerId,
|
|
|
|
|
name = dtoPlayer.name,
|
|
|
|
|
nbBallTouchTotal = dtoPlayer.nbBallTouchTotal,
|
|
|
|
|
timePlayed = dtoPlayer.timePlayed,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await _dataManager.AddPlayer(player);
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: PlayerController/Edit/5
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public ActionResult Edit(int id, IFormCollection collection)
|
|
|
|
|
[HttpDelete("{id}")]
|
|
|
|
|
public async Task<ActionResult> RemovePlayer(int id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
var result = await _dataManager.RemovePlayer(id);
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: PlayerController/Delete/5
|
|
|
|
|
public ActionResult Delete(int id)
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: PlayerController/Delete/5
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public ActionResult Delete(int id, IFormCollection collection)
|
|
|
|
|
[HttpPut("{id}")]
|
|
|
|
|
public async Task<IActionResult> Put(int id, [FromBody] DTOPlayer dtoPlayer)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
if (!ModelState.IsValid)
|
|
|
|
|
return StatusCode((int)HttpStatusCode.BadRequest); //"Les données du player ne sont pas correctes"
|
|
|
|
|
|
|
|
|
|
Player playerTeste = await _dataManager.GetPlayer(id);
|
|
|
|
|
if (playerTeste != null)
|
|
|
|
|
return StatusCode((int)HttpStatusCode.NotFound); //"Le player n'existe pas."
|
|
|
|
|
|
|
|
|
|
var player = new Player
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
playerId = dtoPlayer.playerId,
|
|
|
|
|
name = dtoPlayer.name,
|
|
|
|
|
nbBallTouchTotal = dtoPlayer.nbBallTouchTotal,
|
|
|
|
|
timePlayed = dtoPlayer.timePlayed,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Player playerUpdate = await _dataManager.GetPlayer(id);
|
|
|
|
|
await _dataManager.UpdatePlayer(id,player.name);
|
|
|
|
|
return StatusCode((int)HttpStatusCode.OK); //"Le champion a été modifié."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|