diff --git a/.vs/API/v17/.suo b/.vs/API/v17/.suo index 064ca0b..3dfb49c 100644 Binary files a/.vs/API/v17/.suo and b/.vs/API/v17/.suo differ diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs b/src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs index ad2f3f2..1680ad1 100644 --- a/src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs +++ b/src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs @@ -1,6 +1,7 @@ using ApiLol.Mapper; using DTO; using Microsoft.AspNetCore.Mvc; +using Microsoft.IdentityModel.Tokens; using Model; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -32,7 +33,7 @@ namespace ApiLol.Controllers { var dtos = (await _manager.ChampionsMgr.GetItemsByName(name,0, await _manager.ChampionsMgr.GetNbItems())) .Select(x => x.ToDto()); - if(dtos == null) + if(dtos.IsNullOrEmpty()) { return NotFound(); } @@ -47,18 +48,28 @@ namespace ApiLol.Controllers (await _manager.ChampionsMgr.AddItem(champion.ToModel())).ToDto()); } -/* // PUT api//5 + // PUT api//5 [HttpPut("{name}")] - public async void Put(string name, [FromBody] ChampionDto champion) + public async Task Put(string name, [FromBody] ChampionDto champion) { - return Ok(await _manager.ChampionsMgr.UpdateItem(, champion.ToModel())); - }*/ + var dtos = (await _manager.ChampionsMgr.GetItemsByName(name, 0, await _manager.ChampionsMgr.GetNbItems())); + if(dtos.IsNullOrEmpty()) + { + return BadRequest(); + } + return Ok(await _manager.ChampionsMgr.UpdateItem(dtos.First(), champion.ToModel())); + } // DELETE api//5 - [HttpDelete] - public async Task Delete([FromBody] ChampionDto champion) + [HttpDelete("{name}")] + public async Task Delete(string name) { - return Ok(await _manager.ChampionsMgr.DeleteItem(champion.ToModel())); + var dtos = (await _manager.ChampionsMgr.GetItemsByName(name, 0, await _manager.ChampionsMgr.GetNbItems())); + if (dtos.IsNullOrEmpty()) + { + return BadRequest(); + } + return Ok(await _manager.ChampionsMgr.DeleteItem(dtos.First())); } } } diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs index 32ab8a7..dbb9679 100644 --- a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs +++ b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs @@ -11,15 +11,15 @@ namespace ApiLol.Mapper { Name = champion.Name, Bio = champion.Bio, + Class = champion.Class.ToDto(), + Icon = champion.Icon, + Image = champion.Image.Base64 }; } public static Champion ToModel(this ChampionDto championDto) { - return new Champion(championDto.Name) - { - Bio = championDto.Bio, - }; + return new Champion(championDto.Name, championDto.Class.ToModel(), championDto.Icon, championDto.Image,championDto.Bio); } } diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/SkinMapper.cs b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/SkinMapper.cs new file mode 100644 index 0000000..a093e12 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/SkinMapper.cs @@ -0,0 +1,18 @@ +using DTO; + +namespace ApiLol.Mapper +{ + public static class SkinMapper + { + public static SkinDto ToDto(this SkinDto skin) + { + return new SkinDto() + { + Name = skin.Name, + Description = skin.Description, + Icon = skin.Icon, + Price = skin.Price + }; + } + } +} diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/enums/ChampionClassMapper.cs b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/enums/ChampionClassMapper.cs new file mode 100644 index 0000000..c0c52ed --- /dev/null +++ b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/enums/ChampionClassMapper.cs @@ -0,0 +1,17 @@ +using DTO; +using Model; + +namespace ApiLol.Mapper +{ + public static class ChampionClassMapper + { + public static ChampionClassDto ToDto(this ChampionClass championClass) + { + return (ChampionClassDto) championClass; + } + public static ChampionClass ToModel(this ChampionClassDto championClass) + { + return (ChampionClass) championClass; + } + } +} diff --git a/src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs b/src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs index f19a03b..09f009b 100644 --- a/src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs +++ b/src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs @@ -4,5 +4,10 @@ { public string Name { get; set; } public string Bio { get; set; } + public ChampionClassDto Class { get; set; } + public string Icon { get; set; } + public string Image { get; set; } + public IEnumerable Skins { get; set; } + } } \ No newline at end of file diff --git a/src/EntityFramework_LoL/Sources/DTO/SkinDto.cs b/src/EntityFramework_LoL/Sources/DTO/SkinDto.cs new file mode 100644 index 0000000..2c3962b --- /dev/null +++ b/src/EntityFramework_LoL/Sources/DTO/SkinDto.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class SkinDto + { + public string Name { get; set; } + public string Description { get; set; } + public string Icon { get; set; } + public float Price { get; set; } + + } +} diff --git a/src/EntityFramework_LoL/Sources/DTO/enums/ChampionClassDto.cs b/src/EntityFramework_LoL/Sources/DTO/enums/ChampionClassDto.cs new file mode 100644 index 0000000..2f7e82d --- /dev/null +++ b/src/EntityFramework_LoL/Sources/DTO/enums/ChampionClassDto.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public enum ChampionClassDto + { + Unknown, + Assassin, + Fighter, + Mage, + Marksman, + Support, + Tank, + } +}