pull/38/head^2
Corentin R 2 years ago
commit 5280f569ea

@ -0,0 +1,4 @@
[*.cs]
# CS8604: Possible null reference argument.
dotnet_diagnostic.CS8604.severity = none

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -11,12 +11,14 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DTO\DTO.csproj" />
<ProjectReference Include="..\EntityFramework\EntityFramework.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\StubLib\StubLib.csproj" />
</ItemGroup>

@ -8,6 +8,8 @@ using System.Drawing;
using System;
using API_LoL.Mapper;
using System.Xml.Linq;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System.Reflection.PortableExecutable;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@ -21,20 +23,33 @@ namespace API_LoL.Controllers
{
public ChampionsController(IDataManager Manager) {
this._logger = LoggerFactory.Create(builder => builder.AddConsole()).CreateLogger<ChampionsController>();
this.ChampionsManager = Manager.ChampionsMgr;
this.SkinsManager = Manager.SkinsMgr;
}
private IChampionsManager ChampionsManager;
private ISkinsManager SkinsManager;
//private StubData stubData;
private ILogger logger;
private readonly ILogger _logger;
// GET api/<ChampionController>/5
[HttpGet("count")]
public async Task<IActionResult> GetCount()
{
_logger.LogInformation(message: "count returned", "Get", "/Champion/Count", 200, DateTime.Now);
return Ok(ChampionsManager.GetNbItems());
}
[HttpGet]
public async Task<IActionResult> Get(string? name = null,String? skill = null, String? characteristic = null,int index = 0,int size =10)
{
if (size - index > 10)
{
_logger.LogError(message : "Oversized","Get","/Champion",400,"name : "+name,"skill : "+skill,"characteristics : "+characteristic,"index : "+index,"size : "+size,DateTime.Now);
return BadRequest();
}
if (!string.IsNullOrEmpty(name))
@ -42,91 +57,188 @@ namespace API_LoL.Controllers
var list = await ChampionsManager.GetItemsByName(name, index, size);
if (list.Count() != 0)
{
_logger.LogInformation(message: "Champion returned by name", "Get", "/Champion", 200, "name : " + name, "skill : " + skill, "characteristic : " + characteristic, "index : " + index, "size : " + size, DateTime.Now);
return Ok(list.Select(champion => champion?.ToDTO()));
}
else { return NoContent(); }
else {
_logger.LogInformation(message: "No Champion found by name", "Get", "/Champion", 204, "name : " + name, "skill : " + skill, "characteristic : " + characteristic, "index : " + index, "size : " + size, DateTime.Now);
return NoContent(); }
}
else if(!string.IsNullOrEmpty(skill)) {
var list = await ChampionsManager.GetItemsBySkill(skill, index, size);
if (list.Count() != 0)
{
_logger.LogInformation(message: "Champion returned by skill", "Get", "/Champion", 200, "name : " + name, "skill : " + skill, "characteristic : " + characteristic, "index : " + index, "size : " + size, DateTime.Now);
return Ok(list.Select(champion => champion?.ToDTO()));
}
else { return NoContent(); }
else {
_logger.LogInformation(message: "No Champion found by skill", "Get", "/Champion", 204, "name : " + name, "skill : " + skill, "characteristic : " + characteristic, "index : " + index, "size : " + size, DateTime.Now);
return NoContent(); }
}
else if(!string.IsNullOrEmpty (characteristic)) {
var list = await ChampionsManager.GetItems(index, size);
if (list.Count() != 0)
{
_logger.LogInformation(message: "Champion returned by characteristic", "Get", "/Champion", 200, "name : " + name, "skill : " + skill, "characteristic : " + characteristic, "index : " + index, "size : " + size, DateTime.Now);
return Ok(list.Select(champion => champion?.ToDTO()));
}
else { return NoContent(); }
else {
_logger.LogInformation(message: "No Champion found by char", "Get", "/Champion", 204, "name : " + name, "skill : " + skill, "characteristic : " + characteristic, "index : " + index, "size : " + size, DateTime.Now);
return NoContent(); }
}
else {
var list = await ChampionsManager.GetItems(index, size);
if (list.Count() != 0)
{
_logger.LogInformation(message: "Champion returned default", "Get", "/Champion", 200, "name : " + name, "skill : " + skill, "characteristic : " + characteristic, "index : " + index, "size : " + size, DateTime.Now);
return Ok(list.Select(champion => champion?.ToDTO()));
}
else { return NoContent(); }
else {
_logger.LogInformation(message: "No Champion found Default", "Get", "/Champion", 204, "name : " + name,"skill : " + skill,"characteristic : "+ characteristic,"index : "+index,"size : "+size, DateTime.Now);
return NoContent();
}
}
}
[HttpGet("name")]
public async Task<IActionResult> GetByName(String name)
{
if (string.IsNullOrEmpty(name)) return BadRequest();
if (string.IsNullOrEmpty(name))
{
_logger.LogError(message: "No paramater given", "Get", "/Champion/Name", 400, "name : " + name, DateTime.Now);
return BadRequest();
}
var list = await ChampionsManager.GetItemsByName(name, 0, 1);
if (list.Count() == 1)
{
_logger.LogInformation(message: "Champion found", "Get", "/Champion/Name", 20, "name : " + name, DateTime.Now);
return Ok(list.Select(champion => champion?.ToDTO()).First());
}
else { return NoContent(); }
else {
_logger.LogInformation(message: "No Champion found", "Get", "/Champion/Name", 204, "name : " + name, DateTime.Now);
return NoContent();
}
}
[HttpGet("name/skins")]
public async Task<IActionResult> GetSkinsByName(String name)
{
if (string.IsNullOrEmpty(name)) return BadRequest();
if (string.IsNullOrEmpty(name))
{
_logger.LogError(message: "No paramater given", "Get", "/Champion/Name/Skins", 400, "name : " + name, DateTime.Now);
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)
var nb = await SkinsManager.GetNbItemsByChampion(list.First());
if (nb != 0)
{
var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, nb);
return Ok(skins.Select(skin => skin?.ToDTO()));
}
else { return NoContent(); }
else {
_logger.LogInformation(message: "No Skin found found", "Get", "/Champion/Name/Skins", 204, "name : " + name, DateTime.Now);
return NoContent(); }
}
else { return NoContent(); }
else {
_logger.LogInformation(message: "No Champion found", "Get", "/Champion/Name/Skins", 204, "name : " + name, DateTime.Now);
return NoContent();
}
}
// POST api/<ChampionController>
[HttpPost]
//[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(); }
//}
// POST api/<ChampionController>
[HttpPost]
public async Task<IActionResult> Post(ChampionDTO champion)
{
if (champion == null)
{
_logger.LogError(message: "Null paramater given", "Post", "/Champion", 422, "champion : " + champion.toString, DateTime.Now);
return UnprocessableEntity();
}
else
{
var list = await ChampionsManager.GetItemsByName(champion.Name, 0, 1);
Champion champ = list.FirstOrDefault();
if (champ != null)
{
if(champ.Name == champion.Name)
{
_logger.LogError(message: "Champion with this id already exists", "Post", "/Champion", 409, "champion : " + champion.toString, DateTime.Now);
return Conflict(champion);
}
}
await ChampionsManager.AddItem(champion.ToChampion());
_logger.LogInformation(message: "Champion created", "Post", "Champion/Name", 201, "champion : " + champion.toString, DateTime.Now);
return CreatedAtAction("Post",champion);
}
}
// PUT api/<ChampionController>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
[HttpPut("name")]
public async Task<IActionResult> Put(string name, ChampionDTO championDTO)
{
if (string.IsNullOrEmpty(name))
{
_logger.LogError(message: "Null paramater given for Name", "Put", "/Champion/Name", 400,"name : "+name, "champion : " + championDTO.toString, DateTime.Now);
return BadRequest();
}
if(championDTO == null)
{
_logger.LogError(message: "Null paramater given for Champion", "Put", "/Champion/Name", 422, "name : " + name, "champion : " + championDTO.toString, DateTime.Now);
return UnprocessableEntity();
}
var list = await ChampionsManager.GetItemsByName(name, 0, 1);
if (list.Count() == 1)
{
_logger.LogInformation(message: "Champion updated", "Put", "Champion/Name", 200, "name : " + name, "champion : " + championDTO.toString, DateTime.Now);
return Ok(ChampionsManager.UpdateItem(list.First(), championDTO.ToChampion()));
}
else {
_logger.LogInformation(message: "No champion Found", "Put", "/Champion/Name", 204, "name : " + name, "champion : " + championDTO.toString, DateTime.Now);
return NoContent();
}
}
// DELETE api/<ChampionController>/5
[HttpDelete("{id}")]
public void Delete(int id)
[HttpDelete("name")]
public async Task<IActionResult> Delete(string name)
{
if (string.IsNullOrEmpty(name))
{
_logger.LogError(message: "Null paramater given for Name", "Delete", "/Champion/Name", 400, "name : " + name, DateTime.Now);
return BadRequest();
}
var list = await ChampionsManager.GetItemsByName(name, 0, 1);
if(list.Count() == 1){
_logger.LogInformation(message: "Champion Deleted", "Delete", "/Champion/Name", 200, "name : " + name, DateTime.Now);
return Ok(await ChampionsManager.DeleteItem(list.First()));
}else {
_logger.LogInformation(message: "No champion Found", "Delete", "/Champion/Name", 204, "name : " + name, DateTime.Now);
return NoContent(); }
}
}
}

@ -12,19 +12,13 @@ namespace DTO.Mapper
{
public static ChampionDTO ToDTO(this Champion champion)
{
return new ChampionDTO(champion.Name, champion.Bio, champion.Icon,champion.Class.ToDTO().ToString());
//return new ChampionDTO(champion.Name, champion.Bio, champion.Icon, champion.Skills);
return new ChampionDTO(champion.Name, champion.Bio, champion.Icon, champion.Class.ToDTO(), champion.Image.Base64);
}
public static Champion ToChampion(this ChampionDTO champion)
{
Champion champ = new Champion(champion.Name, champion.Class.ToChampionClass(), champion.Icon, "", champion.Bio);
return new Champion(champion.Name, champClass: champion.Class.ToChampionClass(),icon: champion.Icon,bio: champion.Bio,image :champion.Image);
//foreach (Skill skill in champion.Skills)
//{
// champ.AddSkill(skill);
//}
return champ;
}
}
}

@ -7,12 +7,12 @@ namespace API_LoL.Mapper
{
public static SkinDTO ToDTO(this Skin skin)
{
return new SkinDTO(skin.Name, skin.Description, skin.Icon);
return new SkinDTO(skin.Name, skin.Description, skin.Icon,skin.Image.Base64,skin.Price);
}
public static Skin ToSkin(this SkinDTO skin)
{
return new Skin(skin.Name, null, icon:skin.Icon) ;
return new Skin(skin.Name, null,price: skin.Price, icon:skin.Icon,image: skin.Image,description: skin.Description) ;
}
}
}

@ -1,6 +1,9 @@
using API_LoL;
using EntityFramework;
using EntityFramework.Manager;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.Extensions.Logging;
using Model;
using StubLib;
@ -11,7 +14,7 @@ var builder = WebApplication.CreateBuilder(args);
///NOT WORKING WHEN CHANGING VERSIONS :
/// voir sur https://blog.christian-schou.dk/how-to-use-api-versioning-in-net-core-web-api/ rubrique "Configure SwaggerOptions"
/// (mais requiere l'injection de dépendance).
/// (mais requiere l'injection de d<EFBFBD>pendance).
/// Sinon, code plus simple disponible par le prof
@ -37,13 +40,24 @@ builder.Services.AddControllers();
builder.Services.AddScoped<IDataManager,StubData>();
//builder.Services.AddScoped<IDataManager,StubData>();
builder.Services.AddHttpClient();
//builder.Services.AddScoped<IDataManager,StubData>();
builder.Services.AddScoped<IDataManager,EFDataManager>();
builder.Services.AddDbContext<LoLDBContextWithStub>();
var app = builder.Build();
using(var scope = app.Services.CreateScope())
{
var context = scope.ServiceProvider.GetService<LoLDBContextWithStub>();
context.Database.EnsureCreated();
}
var apiVersionDescriptionProvider = app.Services.GetRequiredService<IApiVersionDescriptionProvider>();

Binary file not shown.

Binary file not shown.

@ -3,6 +3,7 @@ using DTO;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.Extensions.Logging;
using Model;
using StubLib;
using System.Collections;
@ -21,7 +22,7 @@ namespace Api_UT
public async Task Get_Default_OkList()
{
List<ChampionDTO> list = new List<ChampionDTO> {new ChampionDTO("Akali","","","Assassin"), new ChampionDTO("Aatrox", "", "", "Fighter"), new ChampionDTO("Ahri", "", "", "Mage"), new ChampionDTO("Akshan", "", "", "Marksman"), new ChampionDTO("Bard", "", "","Support"), new ChampionDTO("Alistar", "", "","Tank") };
List<ChampionDTO> list = new List<ChampionDTO> {new ChampionDTO("Akali","","","Assassin",""), new ChampionDTO("Aatrox", "", "", "Fighter",""), new ChampionDTO("Ahri", "", "", "Mage",""), new ChampionDTO("Akshan", "", "", "Marksman",""), new ChampionDTO("Bard", "", "","Support",""), new ChampionDTO("Alistar", "", "","Tank","") };
IActionResult a = await api.Get();
a.Should().NotBeNull();
var aObject = a as OkObjectResult;
@ -42,7 +43,7 @@ namespace Api_UT
[TestMethod]
public async Task Get_2First_OkListOf2()
{
List<ChampionDTO> list = new List<ChampionDTO> { new ChampionDTO("Akali", "", "", "Assassin"), new ChampionDTO("Aatrox", "", "", "Fighter") };
List<ChampionDTO> list = new List<ChampionDTO> { new ChampionDTO("Akali", "", "", "Assassin",""), new ChampionDTO("Aatrox", "", "", "Fighter","") };
IActionResult a = await api.Get(index: 0,size: 2);
@ -57,7 +58,7 @@ namespace Api_UT
[TestMethod]
public async Task Get_FilterAName_OkListOf5()
{
List<ChampionDTO> list = new List<ChampionDTO> { new ChampionDTO("Akali", "", "", "Assassin"), new ChampionDTO("Akshan", "", "", "Marksman") };
List<ChampionDTO> list = new List<ChampionDTO> { new ChampionDTO("Akali", "", "", "Assassin", ""), new ChampionDTO("Akshan", "", "", "Marksman", "") };
IActionResult a = await api.Get(name: "Ak");
@ -75,10 +76,12 @@ namespace Api_UT
public async Task Post_ValidChampion_Created()
{
ChampionsController api = new ChampionsController(new StubData());
IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon", "Assassin"));
IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon", "Assassin",""));
var action = (CreatedAtActionResult)a;
var champAction = action.Value as IEnumerable<ChampionDTO>;
Assert.IsNotNull(a);
ChampionDTO champ = new ChampionDTO("nom", "bio", "icon","Assassin");
Assert.IsTrue(champ.equals((ChampionDTO)((CreatedAtActionResult)a).Value));
ChampionDTO champ = new ChampionDTO("nom", "bio", "icon","Assassin", "");
Assert.IsTrue(champ.equals(other: (ChampionDTO)((CreatedAtActionResult)a).Value));
}
}

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\HttpClient\HttpClient.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,44 @@

using ConsoleApplication;
using EntityFramework;
using HttpClient;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Model;
var builder = WebApplication.CreateBuilder();
builder.Services.AddDbContext<LoLDBContextWithStub>();
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var context = scope.ServiceProvider.GetService<LoLDBContextWithStub>();
context.Database.EnsureCreated();
}
IDataManager dataManager = new HttpClientManager();
string choice = "0";
while (choice != "9")
{
Utils.showMainMenu();
choice = Console.ReadLine();
switch (choice)
{
case "1":
{
Utils.championMenu(dataManager.ChampionsMgr);
break;
}
case "2":
{
//Utils.
break;
}
}
}

@ -0,0 +1,55 @@
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication
{
public static class Utils
{
public static void showMainMenu()
{
Console.WriteLine("-------- Menu -------");
Console.WriteLine(" 1 - Champions ");
Console.WriteLine(" 2 - Skills ");
Console.WriteLine("\n 9 - Quitter");
}
public static void showChampionMenu()
{
Console.WriteLine("-------- Champion -------");
Console.WriteLine(" 1 - Count ");
Console.WriteLine(" 2 - Default ");
Console.WriteLine("\n 9 - Quitter");
}
public static async void championMenu(IChampionsManager championsManager ) {
string choix = "0";
while (choix != "9")
{
Utils.showChampionMenu();
choix = Console.ReadLine();
switch (choix)
{
case "1":
//Console.WriteLine("# result : "+ await championsManager.GetNbItems());
break;
case "2":
var list = await championsManager.GetItems(0, 10);
foreach(var cham in list)
{
Console.WriteLine("# result : " +cham.ToString());
}
break;
}
}
}
}
}

@ -5,17 +5,19 @@ namespace DTO
{
public class ChampionDTO
{
public ChampionDTO(string name, string bio, string icon, string championClassDTO)
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; }
public string Bio { get; set; }
public string Icon { get; set; }
public string Image { get; set; }
public string Class { get; set; }
public bool equals(ChampionDTO other)

@ -13,10 +13,16 @@ namespace DTO
public string Description { get; set; }
public string Icon { get; set; }
public SkinDTO(string name,string description,string icon) {
public string Image { get; set; }
public float Price { get; set; }
public SkinDTO(string name,string description,string icon,string image,float price) {
this.Name = name;
this.Description = description;
this.Icon = icon;
this.Image = image;
this.Price = price;
}
}

@ -0,0 +1,53 @@
using EntityFramework;
using EntityFramework.Manager;
using FluentAssertions;
using FluentAssertions.Primitives;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EF_UT
{
[TestClass]
public class EFDataManagerChampionTest
{
[TestMethod]
public void Add_ValidChampion_Added()
{
IDataManager dataManager = new EFDataManager();
IChampionsManager championsManager = dataManager.ChampionsMgr;
var champ = championsManager.AddItem(new Champion("test"));
}
[TestMethod]
public async Task GetItemsByName_DefaultChamp_One()
{
var builder = WebApplication.CreateBuilder();
builder.Services.AddDbContext<LoLDBContextWithStub>();
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var context = scope.ServiceProvider.GetService<LoLDBContextWithStub>();
context.Database.EnsureCreated();
}
IDataManager dataManager = new EFDataManager();
IChampionsManager championsManager = dataManager.ChampionsMgr;
var ak = (await championsManager.GetItemsByName("A", 0, 1)).First();
Assert.IsNotNull(ak);
Assert.AreEqual("Aatrox", ak.Name);
}
}
}

@ -23,11 +23,12 @@ namespace EF_UT
using (var context = new LoLDbContext(options))
{
ChampionEntity chewie = new ChampionEntity("Chewbacca", "", "");
ChampionEntity yoda = new ChampionEntity("Yoda", "", "");
ChampionEntity ewok = new ChampionEntity("Ewok", "", "");
ChampionEntity chewie = new ChampionEntity { Name = "Chewbacca", Bio = "", Icon = "" };
ChampionEntity yoda = new ChampionEntity{ Name = "Yoda", Bio = "", Icon = "" };
ChampionEntity ewok = new ChampionEntity{ Name = "Ewok", Bio = "", Icon = "" };
//SkinEntity defaulSkin = new SkinEntity("Skin Default", chewie);
//chewie.AddSkin(defaulSkin);
Console.WriteLine("Creates and inserts new Champion for tests");
context.Add(chewie);
context.Add(yoda);
@ -54,9 +55,9 @@ namespace EF_UT
//prepares the database with one instance of the context
using (var context = new LoLDbContext(options))
{
ChampionEntity chewie = new ChampionEntity("Chewbacca", "ewa", "");
ChampionEntity yoda = new ChampionEntity("Yoda", "wewo", "");
ChampionEntity ewok = new ChampionEntity("Ewok", "", "");
ChampionEntity chewie = new ChampionEntity{ Name = "Chewbacca", Bio = "ewa", Icon = "" };
ChampionEntity yoda = new ChampionEntity{ Name = "Yoda", Bio = "wewo", Icon = "" };
ChampionEntity ewok = new ChampionEntity{ Name = "Ewok", Bio = "", Icon = "" };
context.Add(chewie);
context.Add(yoda);

@ -32,14 +32,32 @@ namespace EntityFramework
//public ImmutableHashSet<Skill> Skills => skills.ToImmutableHashSet();
//private HashSet<Skill> skills = new HashSet<Skill>();
private ICollection<SkillEntity> Skills { get; set; }
public ICollection<SkillEntity> Skills { get; set; } = new Collection<SkillEntity>();
//public ReadOnlyCollection<SkinEntity> Skins { get; private set; }
//private List<SkinEntity> skins = new();
public ICollection<SkinEntity> skins { get; set; } = new Collection<SkinEntity>();
//public LargeImageEntity? Image { get; set; } ====> voir pour faire "plus propre" => créé une table pour l'entity Largeimage
public string? Image { get; set; }
// Pour le many to many Champion *<---->* RunePage
public ICollection<RunePageEntity> RunePageEntities{ get; set; }
public ChampionEntity(string name,string bio,string icon) {
this.Name = name;
this.Bio = bio;
this.Icon = icon;
Skills= new List<SkillEntity>();
}
/// <summary>
/// pas besoin de constructeur ! (sans lui, il est possible d'utiliser la syntaxe utilisé dans le stubbedbDBCOntext)
/// </summary>
/// <returns></returns>
//public ChampionEntity(string name,string bio,string icon) {
// this.Name = name;
// this.Bio = bio;
// this.Icon = icon;
// Skills= new List<SkillEntity>();
// //Skins = new ReadOnlyCollection<SkinEntity>(skins);
//}
public override string ToString()
{
@ -53,5 +71,15 @@ namespace EntityFramework
public void RemoveSkill(SkillEntity skill)
=> Skills.Remove(skill);
public bool AddSkin(SkinEntity skin)
{
if (skins.Contains(skin))
return false;
skins.Add(skin);
return true;
}
}
}

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
@ -8,6 +8,14 @@
<StartWorkingDirectory>$(MSBuildProjectDirectory)</StartWorkingDirectory>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Manager\EFDataManager.Champion.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Manager\EFDataManager.Champion.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.2" />
@ -18,6 +26,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\StubLib\StubLib.csproj" />
</ItemGroup>

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFramework
{
public enum EnumCategory
{
Major,
Minor1,
Minor2,
Minor3,
OtherMinor1,
OtherMinor2
}
}

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFramework
{
public enum EnumRuneFamily
{
Unknown,
Precision,
Domination
}
}

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFramework
{
public class LargeImageEntity
{
public int Id { get; set; }
public string Base64 { get; set; }
//public LargeImageEntity(string base64)
//{
// Base64 = base64;
//}
}
}

@ -11,6 +11,15 @@ namespace EntityFramework
{
public DbSet<ChampionEntity> Champions { get; set; }
public DbSet<SkinEntity> Skins { get; set; }
public DbSet<LargeImageEntity> Image { get; set; }
public DbSet<RuneEntity> Rune { get; set; }
public DbSet<RunePageEntity> RunePage { get; set; }
public LoLDbContext()
{ }
@ -30,11 +39,11 @@ namespace EntityFramework
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ChampionEntity>().HasKey(entity => entity.Name);
modelBuilder.Entity<ChampionEntity>().ToTable("Champion");
modelBuilder.Entity<ChampionEntity>().ToTable("Champions");
//modelBuilder.Entity<ChampionEntity>().Property(entity => entity.Id)
// .ValueGeneratedOnAdd();
modelBuilder.Entity<ChampionEntity>().Property(entity => entity.Name)
.IsRequired()
.HasMaxLength(50);
@ -46,8 +55,46 @@ namespace EntityFramework
modelBuilder.Entity<ChampionEntity>().Property(entity => entity.Icon)
.IsRequired();
/// One to many
/// ChampionEntity 1 ---> * SkinEntity
//création de la table Skin
modelBuilder.Entity<SkinEntity>().HasKey(skin => skin.Name); //définition de la clé primaire
modelBuilder.Entity<SkinEntity>().Property(skin => skin.Name)
.ValueGeneratedOnAdd(); //définition du mode de génération de la clé : génération à l'insertion
// Add the shadow property to the model
modelBuilder.Entity<SkinEntity>()
.Property<string>("ChampionEntityForeignKey");
// Use the shadow property as a foreign key
modelBuilder.Entity<SkinEntity>()
.HasOne(skin => skin.Champion)
.WithMany(champion => champion.skins)
.HasForeignKey("ChampionEntityForeignKey");
// Many to Many ChampionEntity - RunePageEntity
modelBuilder.Entity<RuneEntity>().HasKey(entity => entity.Name);
modelBuilder.Entity<RunePageEntity>().HasKey(entity => entity.Name);
modelBuilder.Entity<RunePageEntity>().ToTable("RunePage");
// Use the shadow property as a foreign key
modelBuilder.Entity<RunePageEntity>()
.HasMany(r => r.Champion)
.WithMany(c => c.RunePageEntities);
//.HasForeignKey("AlbumForeignKey");
modelBuilder.Entity<ChampionEntity>()
.HasMany(c => c.RunePageEntities)
.WithMany(r => r.Champion);
//.HasForeignKey("AlbumForeignKey");
}
}
}

@ -0,0 +1,186 @@
using EntityFramework.Mapper;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFramework.Manager
{
public partial class EFDataManager
{
public class ChampionsManager : IChampionsManager
{
private readonly EFDataManager parent;
public ChampionsManager(EFDataManager parent)
{
this.parent = parent;
}
public async Task<Champion?> AddItem(Champion? item)
{
using(var context = new LoLDBContextWithStub())
{
if (item != null)
{
context.Add(item.ToEntity());
context.SaveChanges();
return item;
}
else
{
throw new Exception();
}
}
}
public async Task<bool> DeleteItem(Champion? item)
{
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)
{
using(var context = new LoLDBContextWithStub() )
{
var champ = context.Champions.ToArray();
if (descending == false)
{
return champ.ToList().Skip(index * count).Take(count).Select(c => c.ToChampion()).OrderBy(c => c.Name);
}
else
{
return champ.ToList().Skip(index * count).Take(count).Select(c => c.ToChampion()).OrderByDescending(c => c.Name);
}
}
}
public Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByClass(Model.ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public async Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
using (var context = new LoLDBContextWithStub())
{
var champ = context.Champions.Where(c => c.Name.Contains(substring)).AsEnumerable();
if (descending == false)
{
return champ.Select(c => c.ToChampion()).ToList().Skip(index * count).Take(count).OrderBy(c=> c.Name);
}
else
{
return champ.Select(c => c.ToChampion()).ToList().Skip(index*count).Take(count).OrderByDescending(c => c.Name);
}
}
}
public Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public async Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
using(var context = new LoLDBContextWithStub())
{
var champ = context.Champions.Where(c => c.Skills.Any(c => c.Name.Contains(skill)));
if (descending.Equals(false))
{
return champ.Select(c=> c.ToChampion()).ToList().Skip(index * count).Take(count).OrderBy(c => c.Name);
}
else
{
return champ.Select(c => c.ToChampion()).ToList().Skip(index * count).Take(count).OrderByDescending(c => c.Name);
}
}
}
public async Task<int> GetNbItems()
{
using(var context = new LoLDBContextWithStub())
{
return context.Champions.Count();
}
}
public Task<int> GetNbItemsByCharacteristic(string charName)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByClass(Model.ChampionClass championClass)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByName(string substring)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByRunePage(RunePage? runePage)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsBySkill(Skill? skill)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsBySkill(string skill)
{
throw new NotImplementedException();
}
public async Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
{
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(); }
}
}
}
}
}

@ -0,0 +1,85 @@
using EntityFramework.Mapper;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFramework.Manager
{
public partial class EFDataManager
{
public class SkinsManager : ISkinsManager
{
private readonly EFDataManager parent;
public SkinsManager(EFDataManager parent)
{
this.parent = parent;
}
public Task<Skin?> AddItem(Skin? item)
{
throw new NotImplementedException();
}
public Task<bool> DeleteItem(Skin? item)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Skin?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public async Task<IEnumerable<Skin?>> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
using (var context = new LoLDBContextWithStub())
{
var skins = context.Skins.Where(c => c.Champion.Equals(champion)).ToList();
if (descending == false)
{
return skins.Select(c => c.ToSkin()).ToList().Skip(index * count).Take(count).OrderBy(c => c.Name);
}
else
{
return skins.Select(c => c.ToSkin()).ToList().Skip(index * count).Take(count).OrderByDescending(c => c.Name);
}
}
}
public Task<IEnumerable<Skin?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<int> GetNbItems()
{
throw new NotImplementedException();
}
public async Task<int> GetNbItemsByChampion(Champion? champion)
{
using(var context = new LoLDBContextWithStub())
{
return context.Skins.Where(c => c.Champion.Equals(champion.ToEntity())).Count();
}
}
public Task<int> GetNbItemsByName(string substring)
{
throw new NotImplementedException();
}
public Task<Skin?> UpdateItem(Skin? oldItem, Skin? newItem)
{
throw new NotImplementedException();
}
}
}
}

@ -0,0 +1,25 @@
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFramework.Manager
{
public partial class EFDataManager : IDataManager
{
public EFDataManager() {
ChampionsMgr = new ChampionsManager(this);
SkinsMgr = new SkinsManager(this);
}
public IChampionsManager ChampionsMgr { get; }
public ISkinsManager SkinsMgr { get; }
public IRunesManager RunesMgr { get; }
public IRunePagesManager RunePagesMgr { get; }
}
}

@ -10,7 +10,13 @@ namespace EntityFramework.Mapper
public static class ChampionMapper
{
public static ChampionEntity ToEntity(this Champion champion) {
return new ChampionEntity(champion.Name, champion.Bio, champion.Icon);
return new ChampionEntity { Name = champion.Name, Bio = champion.Bio, Icon = champion.Icon };
}
public static Champion ToChampion(this ChampionEntity champion)
{
return new Champion(champion.Name,bio: champion.Bio,icon: champion.Icon);
}
}
}

@ -0,0 +1,24 @@
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFramework.Mapper
{
public static class SkinMapper
{
public static SkinEntity ToEntity(this Skin skin)
{
return new SkinEntity { Champion = skin.Champion.ToEntity(), Description = skin.Description, Icon = skin.Icon, Image = skin.Image.Base64, Name = skin.Name, Price = skin.Price };
}
public static Skin ToSkin(this SkinEntity entity)
{
return new Skin(entity.Name,entity.Champion.ToChampion(),price: entity.Price,icon: entity.Icon, image: entity.Image,description: entity.Description);
}
}
}

@ -1,83 +0,0 @@
// <auto-generated />
using EntityFramework;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFramework.Migrations
{
[DbContext(typeof(LoLDBContextWithStub))]
[Migration("20230312170120_stubMig")]
partial class stubMig
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
{
b.Property<string>("Name")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Bio")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("string")
.HasColumnName("Bio");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("Champion", (string)null);
b.HasData(
new
{
Name = "Akali",
Bio = "",
Icon = ""
},
new
{
Name = "Aatrox",
Bio = "",
Icon = ""
},
new
{
Name = "Ahri",
Bio = "",
Icon = ""
},
new
{
Name = "Akshan",
Bio = "",
Icon = ""
},
new
{
Name = "Bard",
Bio = "",
Icon = ""
},
new
{
Name = "Alistar",
Bio = "",
Icon = ""
});
});
#pragma warning restore 612, 618
}
}
}

@ -1,49 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace EntityFramework.Migrations
{
/// <inheritdoc />
public partial class stubMig : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Champion",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
Bio = table.Column<string>(type: "string", maxLength: 500, nullable: false),
Icon = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Champion", x => x.Name);
});
migrationBuilder.InsertData(
table: "Champion",
columns: new[] { "Name", "Bio", "Icon" },
values: new object[,]
{
{ "Aatrox", "", "" },
{ "Ahri", "", "" },
{ "Akali", "", "" },
{ "Akshan", "", "" },
{ "Alistar", "", "" },
{ "Bard", "", "" }
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Champion");
}
}
}

@ -1,80 +0,0 @@
// <auto-generated />
using EntityFramework;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFramework.Migrations
{
[DbContext(typeof(LoLDBContextWithStub))]
partial class LoLDBContextWithStubModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
{
b.Property<string>("Name")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Bio")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("string")
.HasColumnName("Bio");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("Champion", (string)null);
b.HasData(
new
{
Name = "Akali",
Bio = "",
Icon = ""
},
new
{
Name = "Aatrox",
Bio = "",
Icon = ""
},
new
{
Name = "Ahri",
Bio = "",
Icon = ""
},
new
{
Name = "Akshan",
Bio = "",
Icon = ""
},
new
{
Name = "Bard",
Bio = "",
Icon = ""
},
new
{
Name = "Alistar",
Bio = "",
Icon = ""
});
});
#pragma warning restore 612, 618
}
}
}

@ -1,12 +1,16 @@
// See https://aka.ms/new-console-template for more information
using EntityFramework;
using EntityFramework.Manager;
using Microsoft.EntityFrameworkCore;
using Model;
using System.Buffers.Text;
using( var context = new LoLDbContext())
using ( var context = new LoLDbContext())
{
context.Add(new ChampionEntity("test","test","test") );
//context.Add(new ChampionEntity{ Name = "test", Bio = "test", Icon = "test" } );
context.SaveChanges();
ChampionEntity champ = context.Find<ChampionEntity>(1);
ChampionEntity champ = context.Find<ChampionEntity>("Akali");
if( champ != null)
{
@ -20,18 +24,109 @@ using( var context = new LoLDbContext())
}
//Test BDD Skills
ChampionEntity champSkill = new ChampionEntity("nomSkill", "bioSkill", "iconSkill");
ChampionEntity champSkill = new ChampionEntity { Name="nomSkill", Bio="bioSkill", Icon="iconSkill" };
SkillEntity s1 = new SkillEntity("Skill1", "desc", SkillType.Unknown);
SkillEntity s2 = new SkillEntity("Skill2", "desc2", SkillType.Ultimate);
SkillEntity s3 = new SkillEntity("Skill3", "desc3", SkillType.Passive);
//SkillEntity s1 = new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown };
SkillEntity s2 = new SkillEntity { Name="Skill2", Description="desc2", Type= EntityFramework.SkillType.Ultimate };
SkillEntity s3 = new SkillEntity { Name = "Skill3", Description = "desc3", Type = EntityFramework.SkillType.Passive };
champSkill.AddSkill(s1);
champSkill.AddSkill(new SkillEntity { Name = "Skill1", Description = "desc", Type = EntityFramework.SkillType.Unknown });
champSkill.AddSkill(s2);
champSkill.AddSkill(s3);
context.Add(champSkill);
context.SaveChanges();
IDataManager dataManager = new EFDataManager();
IChampionsManager championsManager = dataManager.ChampionsMgr;
IEnumerable<Champion?> champions = await championsManager.GetItemsByName("A", 0, 1);
Console.WriteLine(champions.First().Name);
//using ( var context = new LoLDbContext())
//{
// //context.Add(new ChampionEntity{ Name = "test", Bio = "test", Icon = "test" } );
// context.SaveChanges();
// ChampionEntity champ = context.Find<ChampionEntity>("Akali");
// if( champ != null)
// {
// Console
// .WriteLine(champ.ToString());
// }
// else
// {
// Console.WriteLine("Not Found");
// }
// //Test BDD Skills
// ChampionEntity champSkill = new ChampionEntity { Name="nomSkill", Bio="bioSkill", Icon="iconSkill" };
// //SkillEntity s1 = new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown };
// SkillEntity s2 = new SkillEntity { Name="Skill2", Description="desc2", Type=SkillType.Ultimate };
// SkillEntity s3 = new SkillEntity { Name = "Skill3", Description = "desc3", Type = SkillType.Passive };
// champSkill.AddSkill(new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown });
// champSkill.AddSkill(s2);
// champSkill.AddSkill(s3);
// context.Add(champSkill);
// context.SaveChanges();
// //OneToMany
// Console.WriteLine("Champions : ");
// foreach (var champi in context.Champions.Include(a => a.skins))
// {
// Console.WriteLine($"\t{champi.Name} : {champi.Bio}");
// foreach (var s in champi.skins)
// {
// Console.WriteLine($"\t\t{s.Name}");
// }
// }
// Console.WriteLine();
// Console.WriteLine("Skin :");
// foreach (var s in context.Skins)
// {
// Console.WriteLine($"\t{s.Name}: {s.Description} (Champion : {s.Champion.Name})");
// }
var r1 = new RuneEntity { Name = "Rune1", Description = "aaa", Family = EnumRuneFamily.Domination, Image = new LargeImage("base") };
var r2 = new RuneEntity { Name = "Rune2", Description = "aaa", Family = EnumRuneFamily.Domination, Image = new LargeImage("base") };
var corichard = new ChampionEntity { Name = "Corichard", Bio = "biobio", Icon = "Icon.png" };
var pintrand = new ChampionEntity { Name = "Pintrand", Bio = "biobio", Icon = "Icon.png" };
var rp1 = new RunePageEntity { Name = "RP1", Rune = new RuneEntity { Name = "aa", Description = "aaa", Family = EnumRuneFamily.Domination, Image = new LargeImage("base") }, Champion = new List<ChampionEntity> { corichard } };
var rp2 = new RunePageEntity { Name = "RP2", Rune = new RuneEntity{ Name = "aaa", Description = "aaa", Family = EnumRuneFamily.Domination, Image = new LargeImage("base") }, Champion = new List<ChampionEntity> { pintrand } };
context.Rune.AddRange(new[] { r1, r2 });
context.Champions.AddRange(new[] { corichard, pintrand });
context.RunePage.AddRange(new[] { rp1, rp2 });
context.SaveChanges();
}
// Console.WriteLine("\nAjout d'un Champion et 6 Skins...\n");
// ChampionEntity captainMarvel = new ChampionEntity { Name = "Captain Marvel", Bio="Mais que fait un avenger ici ??", Icon="Icon.png"};
// SkinEntity[] skins = { new SkinEntity {Name = "La Fiesta", Champion = captainMarvel},
// new SkinEntity { Name = "Five Hundred Miles High", Champion = captainMarvel },
// new SkinEntity { Name = "Captain Marvel", Champion = captainMarvel },
// new SkinEntity { Name = "Time's Lie", Champion = captainMarvel },
// new SkinEntity { Name = "Lush Life", Champion = captainMarvel },
// new SkinEntity { Name = "Day Waves", Champion = captainMarvel }
// };
// foreach (var s in skins)
// {
// captainMarvel.skins.Add(s);
// }
// context.Add(captainMarvel);
// context.SaveChanges();
//}

@ -0,0 +1,24 @@
using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFramework
{
//[Table("Rune")]
public class RuneEntity
{
[Key]
public string Name;
public string Description;
public EnumRuneFamily Family;
public LargeImage Image;
}
}

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Model.RunePage;
namespace EntityFramework
{
public class RunePageEntity
{
[Key]
public string Name { get; set; }
public RuneEntity? Rune { get; set; }
//? voir si cela pause probleme
public Dictionary<EnumCategory, Rune> Dico = new Dictionary<EnumCategory, Rune>();
// Pour le many to many Champion *<---->* RunePage
public ICollection<ChampionEntity> Champion{ get; set; }
public void CheckRunes(EnumCategory newRuneCategory){}
public void CheckFamilies(EnumCategory cat1, EnumCategory cat2){}
public void UpdateMajorFamily(EnumCategory minor, bool expectedValue){}
}
}

@ -10,42 +10,44 @@ namespace EntityFramework
public class SkillEntity
{
public SkillType Type { get; private set; }
public SkillType Type { get; set; }
[Key]
public string Name
{
get => name;
private init
{
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException("a Skill needs a name");
}
name = value;
}
}
private readonly string name = null!;
public string Name { get; set; }
//public string Name
//{
// get => name;
// private init
// {
// if (string.IsNullOrWhiteSpace(value))
// {
// throw new ArgumentException("a Skill needs a name");
// }
// name = value;
// }
//}
//private readonly string name = null!;
public string Description
{
get => description;
set
{
if (string.IsNullOrWhiteSpace(value))
{
description = "";
return;
}
description = value;
}
}
private string description = "";
public string Description { get; set; }
//public string Description
//{
// get => description;
// set
// {
// if (string.IsNullOrWhiteSpace(value))
// {
// description = "";
// return;
// }
// description = value;
// }
//}
//private string description = "";
public SkillEntity(string Name, string Description, SkillType Type) {
this.name = Name;
this.Description = Description;
this.Type = Type;
}
//public SkillEntity(string Name, string Description, SkillType Type) {
// this.name = Name;
// this.Description = Description;
// this.Type = Type;
//}
}
}

@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFramework
{
public class SkinEntity //ONE TO MANY
{
public string? Name { get; set; }
public string? Description { get; set; }
//public string Name
//{
// get => name;
// private init
// {
// if (string.IsNullOrWhiteSpace(value))
// {
// throw new ArgumentException("A skin must have a name");
// }
// name = value;
// }
//}
//private readonly string name = null!;
//public string Description
//{
// get => description;
// set
// {
// if (string.IsNullOrWhiteSpace(value))
// {
// description = "";
// return;
// }
// description = value;
// }
//}
//private string description = "";
public string Icon { get; set; } = "";
//public LargeImageEntity Image { get; set; }
public string? Image { get; set; }
public float Price { get; set; }
public ChampionEntity Champion { get; set; }
//public ChampionEntity Champion
//{
// get => champion;
// private init
// {
// if (value == null)
// throw new ArgumentNullException("A skill can't have a null champion");
// champion = value;
// }
//}
//private readonly ChampionEntity champion = null!;
//public SkinEntity(string name, ChampionEntity champion, float price = 0.0f, string icon = "", string image = "", string description = "")
//{
// Name = name;
// Champion = champion;
// //Champion.AddSkin(this);
// Price = price;
// Icon = icon;
// Image = new LargeImageEntity(image);
// Description = description;
//}
}
}

@ -0,0 +1,51 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFramework
{
public class StubbedContext : LoLDbContext
{
//protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
//{
// optionsBuilder.EnableSensitiveDataLogging();
//}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
ChampionEntity corichard = new ChampionEntity { Name = "Corichard", Bio = "biobiobiobio", Icon = "/a/a/a/a" };
ChampionEntity pintrand = new ChampionEntity { Name = "Pintrand", Bio = "mimimimimim", Icon = "/small.png" };
RuneEntity r1 = new RuneEntity { Name = "FirstRune", Description = "desc", Family = EnumRuneFamily.Domination };
RuneEntity r2 = new RuneEntity { Name = "SecondRune", Description = "desc", Family = EnumRuneFamily.Unknown };
//ChampionEntity corichard = new ChampionEntity() { Name = "Corichard", Bio = "biobiobiobio", Icon = "/a/a/a/a", Image = new LargeImageEntity { Base64 = "base" } };
//ChampionEntity pintrand = new ChampionEntity { Name = "Pintrand", Bio = "mimimimimim", Icon = "/small.png", Image = new LargeImageEntity { Base64 = "base" } };
modelBuilder.Entity<ChampionEntity>().HasData(corichard, pintrand);
modelBuilder.Entity<SkinEntity>().HasData(new { Name = "aaaa", ChampionEntityForeignKey = "Corichard", Description = "So What", Icon="/Icon.png", Price=10.0f },
new { Name = "skin", ChampionEntityForeignKey = "Corichard", Description = "So What", Icon = "/Icon.png", Price = 10.0f },
new { Name = "bo", ChampionEntityForeignKey = "Corichard", Description = "So What", Icon = "/Icon.png", Price = 10.0f },
new { Name = "Joulie", ChampionEntityForeignKey = "Corichard", Description = "So What", Icon = "/Icon.png", Price = 10.0f },
new { Name = "Radiance", ChampionEntityForeignKey = "Corichard", Description = "So What", Icon = "/Icon.png", Price = 10.0f },
new { Name = "void", ChampionEntityForeignKey = "Corichard", Description = "So What", Icon = "/Icon.png", Price = 10.0f },
new { Name = "Radiance", ChampionEntityForeignKey = "Pintrand", Description = "So What", Icon = "/Icon.png", Price = 10.0f },
new { Name = "void", ChampionEntityForeignKey = "Pintrand", Description = "So What", Icon = "/Icon.png", Price = 10.0f },
new { Name = "DarkTheme", ChampionEntityForeignKey = "Pintrand", Description = "So What", Icon = "/Icon.png", Price = 10.0f },
new { Name = "gold", ChampionEntityForeignKey = "Pintrand", Description = "So What", Icon = "/Icon.png", Price = 10.0f },
new { Name = "ruby", ChampionEntityForeignKey = "Pintrand", Description = "So What", Icon = "/Icon.png", Price = 10.0f }
);
modelBuilder.Entity<RunePageEntity>().HasData(new { Name = "RP1", Rune = r1, Champion = corichard},
new { Name = "RP2", Rune = r2, Champion = pintrand}
);
}
}
}

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\API_LoL\API_LoL.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,128 @@
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Json;
using System.Reflection;
using System.Reflection.Metadata;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace HttpClient
{
public partial class HttpClientManager
{
public class ChampionManager : IChampionsManager
{
private readonly HttpClientManager parent;
private System.Net.Http.HttpClient httpc;
public string BaseAddress;
public ChampionManager(HttpClientManager parent, System.Net.Http.HttpClient httpc) {
this.httpc = httpc;
this.parent = parent;
}
public async Task<Champion?> AddItem(Champion? item) //return le champion ajouté, null sinon ?
{
if(item==null) throw new ArgumentNullException("item is null");
var response = await httpc.PostAsJsonAsync("/Champion?Name = " + item.Name, item);
return response.IsSuccessStatusCode ? item : null;
}
public async Task<bool> DeleteItem(Champion? item)
{
HttpResponseMessage response = await httpc.DeleteAsync("/Champion?Name=" + item.Name);
return response.IsSuccessStatusCode;
}
public Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return httpc.GetFromJsonAsync<IEnumerable<Champion>>("/Champion?index="+index+"&size="+count);
}
public Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return httpc.GetFromJsonAsync<IEnumerable<Champion>>("/Champion?name="+substring+"&index=" + index + "&size=" + count);
}
public Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<int> GetNbItems()
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByCharacteristic(string charName)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByClass(ChampionClass championClass)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByName(string substring)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByRunePage(RunePage? runePage)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsBySkill(Skill? skill)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsBySkill(string skill)
{
throw new NotImplementedException();
}
public Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
{
throw new NotImplementedException();
}
}
}
}

@ -0,0 +1,29 @@
using Model;
namespace HttpClient
{
public partial class HttpClientManager : IDataManager
{
public System.Net.Http.HttpClient httpC { get; set; } = new System.Net.Http.HttpClient();
public string BaseAddress;
public HttpClientManager() {
ChampionsMgr = new ChampionManager(this, httpC);
httpC.BaseAddress = new Uri("https://localhost:7144/api/");
}
public ISkinsManager SkinsMgr => throw new NotImplementedException();
public IRunesManager RunesMgr => throw new NotImplementedException();
public IRunePagesManager RunePagesMgr => throw new NotImplementedException();
public IChampionsManager ChampionsMgr { get; set; }
}
}

@ -26,6 +26,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Api_UT", "Api_UT\Api_UT.csp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EF_UT", "EF_UT\EF_UT.csproj", "{74F469C3-A94A-4507-9DC7-7DBADCD18173}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClient", "HttpClient\HttpClient.csproj", "{DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -64,6 +66,10 @@ Global
{74F469C3-A94A-4507-9DC7-7DBADCD18173}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74F469C3-A94A-4507-9DC7-7DBADCD18173}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74F469C3-A94A-4507-9DC7-7DBADCD18173}.Release|Any CPU.Build.0 = Release|Any CPU
{DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -8,7 +8,7 @@ namespace StubLib
private List<Champion> champions = new()
{
new Champion("Akali", ChampionClass.Assassin),
new Champion("Aatrox", ChampionClass.Fighter),
new Champion("Aatrox", ChampionClass.Fighter),
new Champion("Ahri", ChampionClass.Mage),
new Champion("Akshan", ChampionClass.Marksman),
new Champion("Bard", ChampionClass.Support),

Loading…
Cancel
Save