Ajout put et delete

pull/28/head
Corentin R 2 years ago
parent 9e00ef300d
commit f6a3075218

@ -103,22 +103,22 @@ namespace API_LoL.Controllers
else { return NoContent(); }
}
[HttpGet("name/skills")]
public async Task<IActionResult> GetSkillsByName(String name)
{
if (string.IsNullOrEmpty(name)) return BadRequest();
var list = await ChampionsManager.GetItemsByName(name, 0, 1);
if (list.Count() == 1)
{
var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, await SkinsManager.GetNbItemsByChampion(list.First()));
if (skins.Count() != 0)
{
return Ok(skins.Select(skin => skin?.ToDTO()));
}
else { return NoContent(); }
}
else { return NoContent(); }
}
//[HttpGet("name/skills")]
//public async Task<IActionResult> GetSkillsByName(String name)
//{
// if (string.IsNullOrEmpty(name)) return BadRequest();
// var list = await ChampionsManager.GetItemsByName(name, 0, 1);
// if (list.Count() == 1)
// {
// var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, await SkinsManager.GetNbItemsByChampion(list.First()));
// if (skins.Count() != 0)
// {
// return Ok(skins.Select(skin => skin?.ToDTO()));
// }
// else { return NoContent(); }
// }
// else { return NoContent(); }
//}
@ -132,6 +132,11 @@ namespace API_LoL.Controllers
}
else
{
var champ = await ChampionsManager.GetItemsByName(champion.Name, 0, 1);
if(champ.FirstOrDefault().Name == champion.Name)
{
return Conflict(champion);
}
await ChampionsManager.AddItem(champion.ToChampion());
return CreatedAtAction("Post",champion);

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -5,12 +5,12 @@ namespace DTO
{
public class ChampionDTO
{
public ChampionDTO(string name, string bio, string icon, string championClassDTO, string image)
public ChampionDTO(string name, string bio, string icon, string Class, string image)
{
Name = name;
Bio = bio;
Icon = icon;
Class = championClassDTO;
this.Class = Class;
Image = image;
}
public string Name { get; set; }

@ -26,7 +26,9 @@ namespace EntityFramework.Manager
{
if (item != null)
{
context.Add(item.ToEntity());
context.SaveChanges();
return item;
}
else
@ -36,9 +38,21 @@ namespace EntityFramework.Manager
}
}
public Task<bool> DeleteItem(Champion? item)
public async Task<bool> DeleteItem(Champion? item)
{
throw new NotImplementedException();
using (var context = new LoLDBContextWithStub())
{
var champ = context.Champions.Select(c => c == item.ToEntity());
if(champ.Count()<1)
{
return false;
}
context.Champions.Remove(item.ToEntity());
context.SaveChanges();
return true;
}
}
public async Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
@ -150,9 +164,19 @@ namespace EntityFramework.Manager
throw new NotImplementedException();
}
public Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
public async Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
{
throw new NotImplementedException();
using(var context = new LoLDBContextWithStub())
{
if (oldItem != null && newItem != null)
{
var champ = context.Champions.Where(c => c == oldItem.ToEntity()).First();
champ = newItem.ToEntity();
context.SaveChanges();
return newItem;
}
else { throw new Exception(); }
}
}
}
}

Loading…
Cancel
Save