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 _logger; private List champions = new List(); public ChampionController(ILogger 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> Get() { IEnumerable champs = new List(); foreach(ChampionEntity arg in champions) { champs.Append(arg.ToDto()); } return Ok(champs); } // GET api/values/5 [HttpGet("{id}")] public ActionResult 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) { } } }