You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.5 KiB

using System;
using EFLib;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace ApiLol.Controllers
{
[Route("api/[controller]")]
public class ChampionController : ControllerBase
{
private readonly ILogger<ChampionController> _logger;
private List<ChampionEntity> champions = new List<ChampionEntity>();
public ChampionController(ILogger<ChampionController> logger)
{
_logger = logger;
champions.Add(new ChampionEntity
{
Id = 1,
Name = "Aurel",
Bio = "Trop joli",
Icon = "Moi",
ChampClass = Model.ChampionClass.Tank
});
champions.Add(new ChampionEntity
{
Id = 2,
Name = "Mathilde",
Bio = "Elle est reloue",
Icon = "Macheval",
ChampClass = Model.ChampionClass.Assassin
});
}
// GET: api/champion
[HttpGet]
public ActionResult<IEnumerable<ChampionDTO>> Get()
{
IEnumerable<ChampionDTO> champs = new List<ChampionDTO>();
foreach(ChampionEntity arg in champions)
{
champs.Append(arg.ToDto());
}
return Ok(champs);
}
// GET api/values/5
[HttpGet("{id}")]
public ActionResult<ChampionDTO?> Get(int id)
{
ChampionDTO? champion = champions.SingleOrDefault((ChampionEntity arg) => arg.Id == id)?.ToDto();
if (champion != null)
{
return Ok(champion);
}
return BadRequest();
}
// POST api/values
[HttpPost]
public void Post([FromBody]int id, string name, string bio, string icon)
{
if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(bio) || string.IsNullOrWhiteSpace(icon)){
BadRequest();
}
else
{
Ok();
}
}
// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}