diff --git a/Sources/ConsoleAPI/ConsoleAPI.csproj b/Sources/ConsoleAPI/ConsoleAPI.csproj
new file mode 100644
index 0000000..a476915
--- /dev/null
+++ b/Sources/ConsoleAPI/ConsoleAPI.csproj
@@ -0,0 +1,14 @@
+
+
+
+ Exe
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/Sources/ConsoleAPI/Program.cs b/Sources/ConsoleAPI/Program.cs
new file mode 100644
index 0000000..a0e0d57
--- /dev/null
+++ b/Sources/ConsoleAPI/Program.cs
@@ -0,0 +1,65 @@
+using Web_Api;
+
+namespace ConsoleAPI
+{
+ class Program
+ {
+ static async Task Main(string[] args)
+ {
+ using (var client = new HttpClient())
+ {
+ // définit l'URL de votre API
+ client.BaseAddress = new Uri("https://localhost:7189/api/Champions");
+
+ // exécute la requete HTTP GET
+ HttpResponseMessage response = await client.GetAsync("");
+
+ // vérifie si la réponse est valide
+ if (response.IsSuccessStatusCode)
+ {
+ // lit le contenu de la réponse
+ string result = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(result);
+ }
+ else
+ {
+ Console.WriteLine("Erreur : " + response.StatusCode);
+ }
+
+ // exécute la requête HTTP GET pour obtenir un champion par nom
+ HttpResponseMessage response1 = await client.GetAsync("/Akali");
+
+ if (response1.IsSuccessStatusCode)
+ {
+ // lit le contenu de la réponse
+ string result = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(result);
+ }
+ else
+ {
+ Console.WriteLine("Erreur : " + response.StatusCode);
+ }
+
+ // exécute la requête HTTP POST pour ajouter un champion
+ var champion = new ChampionDTO
+ {
+ Name = "Ashe",
+ Bio = "La Comtesse du froid",
+ };
+ /*response = await client.PostAsync("/addChampion", new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(champion), System.Text.Encoding.UTF8, "application/json"));
+ HttpResponseMessage response = await client.PostAsync("/addChampion", Content);*/
+
+ // vérifie si la réponse est valide
+ if (response.IsSuccessStatusCode)
+ {
+ Console.WriteLine("Le champion a été ajouté avec succès");
+ }
+ else
+ {
+ Console.WriteLine("Erreur : " + response.StatusCode);
+ }
+
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Sources/ConsoleApp/ConsoleApp.csproj b/Sources/ConsoleApp/ConsoleApp.csproj
new file mode 100644
index 0000000..74abf5c
--- /dev/null
+++ b/Sources/ConsoleApp/ConsoleApp.csproj
@@ -0,0 +1,10 @@
+
+
+
+ Exe
+ net6.0
+ enable
+ enable
+
+
+
diff --git a/Sources/ConsoleApp/Program.cs b/Sources/ConsoleApp/Program.cs
new file mode 100644
index 0000000..3751555
--- /dev/null
+++ b/Sources/ConsoleApp/Program.cs
@@ -0,0 +1,2 @@
+// See https://aka.ms/new-console-template for more information
+Console.WriteLine("Hello, World!");
diff --git a/Sources/ConsoleDbSQLite/ConsoleDbSQLite.csproj b/Sources/ConsoleDbSQLite/ConsoleDbSQLite.csproj
new file mode 100644
index 0000000..c112e42
--- /dev/null
+++ b/Sources/ConsoleDbSQLite/ConsoleDbSQLite.csproj
@@ -0,0 +1,24 @@
+
+
+
+ Exe
+ net6.0
+ enable
+ enable
+ $(MSBuildProjectDirectory)
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
diff --git a/Sources/ConsoleDbSQLite/Migrations/20230201115946_migration_ConsoleDbSQLite.Designer.cs b/Sources/ConsoleDbSQLite/Migrations/20230201115946_migration_ConsoleDbSQLite.Designer.cs
new file mode 100644
index 0000000..d789e8a
--- /dev/null
+++ b/Sources/ConsoleDbSQLite/Migrations/20230201115946_migration_ConsoleDbSQLite.Designer.cs
@@ -0,0 +1,46 @@
+//
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace ConsoleDbSQLite.Migrations
+{
+ [DbContext(typeof(SQLiteLolContext))]
+ [Migration("20230201115946_migration_ConsoleDbSQLite")]
+ partial class migrationConsoleDbSQLite
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
+
+ modelBuilder.Entity("EntityFrameworkLib.ChampionEntity", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("Bio")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Icon")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.ToTable("Champions");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/Sources/ConsoleDbSQLite/Migrations/20230201115946_migration_ConsoleDbSQLite.cs b/Sources/ConsoleDbSQLite/Migrations/20230201115946_migration_ConsoleDbSQLite.cs
new file mode 100644
index 0000000..1f2cbe3
--- /dev/null
+++ b/Sources/ConsoleDbSQLite/Migrations/20230201115946_migration_ConsoleDbSQLite.cs
@@ -0,0 +1,36 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace ConsoleDbSQLite.Migrations
+{
+ ///
+ public partial class migrationConsoleDbSQLite : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "Champions",
+ columns: table => new
+ {
+ Id = table.Column(type: "INTEGER", nullable: false)
+ .Annotation("Sqlite:Autoincrement", true),
+ Name = table.Column(type: "TEXT", nullable: false),
+ Bio = table.Column(type: "TEXT", nullable: false),
+ Icon = table.Column(type: "TEXT", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Champions", x => x.Id);
+ });
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "Champions");
+ }
+ }
+}
diff --git a/Sources/ConsoleDbSQLite/Migrations/SQLiteLolContextModelSnapshot.cs b/Sources/ConsoleDbSQLite/Migrations/SQLiteLolContextModelSnapshot.cs
new file mode 100644
index 0000000..a15aaf0
--- /dev/null
+++ b/Sources/ConsoleDbSQLite/Migrations/SQLiteLolContextModelSnapshot.cs
@@ -0,0 +1,43 @@
+//
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace ConsoleDbSQLite.Migrations
+{
+ [DbContext(typeof(SQLiteLolContext))]
+ partial class SQLiteLolContextModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
+
+ modelBuilder.Entity("EntityFrameworkLib.ChampionEntity", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("Bio")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Icon")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.ToTable("Champions");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/Sources/ConsoleDbSQLite/Program.cs b/Sources/ConsoleDbSQLite/Program.cs
new file mode 100644
index 0000000..0de637c
--- /dev/null
+++ b/Sources/ConsoleDbSQLite/Program.cs
@@ -0,0 +1,69 @@
+// See https://aka.ms/new-console-template for more information
+
+using DBEntitiesWithStub;
+using EntityFrameworkLib;
+using Microsoft.EntityFrameworkCore;
+
+ChampionEntity jax = new ChampionEntity
+{
+ Name = "Jax",
+ Icon = "icon Jax",
+ Bio = "bio Jax"
+};
+ChampionEntity darius = new ChampionEntity
+{
+ Name = "Darius",
+ Icon = "icon Darius",
+ Bio = "bio Darius"
+};
+ChampionEntity garen = new ChampionEntity
+{
+ Name = "Garen",
+ Icon = "icon Garen",
+ Bio = "bio Garen"
+};
+ChampionEntity veigar = new ChampionEntity
+{
+ Name = "Veigar",
+ Icon = "icon Veigar",
+ Bio = "bio Veigar"
+};
+
+using (var context = new SQLiteLolContext())
+{
+ Console.WriteLine("Creates and inserts new Champion");
+ /*context.Add(garen);
+ context.Add(darius);
+ context.Add(jax);
+ context.Add(veigar);*/
+ context.SaveChanges();
+}
+
+using (var context = new SQLiteLolContext())
+{
+ foreach(var n in context.Champions)
+ {
+ Console.WriteLine($"{n.Id} {n.Name}");
+ }
+ context.SaveChanges();
+}
+
+using (LolContext db = new ChampionsDBEntitiesWithStub())
+{
+ Console.WriteLine("Contenu de la base :");
+ foreach(var n in db.Champions)
+ {
+ Console.WriteLine($"\t{n.Id} - {n.Name} - {n.Bio} - {n.Icon}");
+ }
+}
+
+ public class SQLiteLolContext : LolContext
+{
+ protected override void OnConfiguring(DbContextOptionsBuilder options)
+ {
+ if (!options.IsConfigured)
+ {
+ options.UseSqlite($"Data Source=projet.Champions.db");
+ }
+ }
+}
\ No newline at end of file
diff --git a/Sources/ConsoleDbSQLite/Properties/launchSettings.json b/Sources/ConsoleDbSQLite/Properties/launchSettings.json
new file mode 100644
index 0000000..d63222a
--- /dev/null
+++ b/Sources/ConsoleDbSQLite/Properties/launchSettings.json
@@ -0,0 +1,12 @@
+{
+ "profiles": {
+ "ConsoleDbSQLite": {
+ "commandName": "Project",
+ "launchBrowser": true,
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ },
+ "applicationUrl": "https://localhost:63787;http://localhost:63795"
+ }
+ }
+}
\ No newline at end of file
diff --git a/Sources/EntityFrameworkLib/projet.Champions.db b/Sources/ConsoleDbSQLite/projet.Champions.db
similarity index 95%
rename from Sources/EntityFrameworkLib/projet.Champions.db
rename to Sources/ConsoleDbSQLite/projet.Champions.db
index e4346c3..d8427a2 100644
Binary files a/Sources/EntityFrameworkLib/projet.Champions.db and b/Sources/ConsoleDbSQLite/projet.Champions.db differ
diff --git a/Sources/ConsoleSqlLite/ConsoleSqlLite.csproj b/Sources/ConsoleSqlLite/ConsoleSqlLite.csproj
new file mode 100644
index 0000000..7aeb08a
--- /dev/null
+++ b/Sources/ConsoleSqlLite/ConsoleSqlLite.csproj
@@ -0,0 +1,22 @@
+
+
+
+ net6.0
+ enable
+ enable
+ $(MSBuildProjectDirectory)
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
diff --git a/Sources/DBEntitiesWithStub/ChampionsDBEntitiesWithStub.cs b/Sources/DBEntitiesWithStub/ChampionsDBEntitiesWithStub.cs
new file mode 100644
index 0000000..0915884
--- /dev/null
+++ b/Sources/DBEntitiesWithStub/ChampionsDBEntitiesWithStub.cs
@@ -0,0 +1,20 @@
+using EntityFrameworkLib;
+using Microsoft.EntityFrameworkCore;
+using Model;
+
+namespace DBEntitiesWithStub
+{
+ public class ChampionsDBEntitiesWithStub : LolContext
+ {
+ protected override void OnModelCreating(ModelBuilder modelBuilder)
+ {
+ base.OnModelCreating(modelBuilder);
+
+ modelBuilder.Entity().HasData(
+ new ChampionEntity { Id = 1, Name = "Yone", Bio = "Bio de Yone", Icon = "Icon de Yone" },
+ new ChampionEntity { Id = 2, Name = "Akali", Bio = "Bio de Akali", Icon = "Icon de Akali" },
+ new ChampionEntity { Id = 3, Name = "Bard", Bio = "Bio de Bard", Icon = "Icon de Bard" }
+ );
+ }
+ }
+}
\ No newline at end of file
diff --git a/Sources/DBEntitiesWithStub/DBEntitiesWithStub.csproj b/Sources/DBEntitiesWithStub/DBEntitiesWithStub.csproj
new file mode 100644
index 0000000..84c39a9
--- /dev/null
+++ b/Sources/DBEntitiesWithStub/DBEntitiesWithStub.csproj
@@ -0,0 +1,18 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Sources/EntityFrameworkLib/ChampionEntity.cs b/Sources/EntityFrameworkLib/ChampionEntity.cs
index 6232d8d..88796d8 100644
--- a/Sources/EntityFrameworkLib/ChampionEntity.cs
+++ b/Sources/EntityFrameworkLib/ChampionEntity.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Design;
+using Model;
namespace EntityFrameworkLib
{
@@ -13,5 +14,7 @@ namespace EntityFrameworkLib
public string Name { get; set; }
public string Bio { get; set; }
public string Icon { get; set; }
+ public LargeImage Image { get; set; }
+ public ChampionClass Class { get; set; }
}
}
diff --git a/Sources/EntityFrameworkLib/DBChampionManager.cs b/Sources/EntityFrameworkLib/DBChampionManager.cs
new file mode 100644
index 0000000..f3f8f41
--- /dev/null
+++ b/Sources/EntityFrameworkLib/DBChampionManager.cs
@@ -0,0 +1,126 @@
+using EntityFrameworkLib.Mappers;
+using Model;
+using Shared;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EntityFrameworkLib
+{
+ public class DBChampionManager : IChampionsManager
+ {
+ private readonly LolContext context;
+
+ public DBChampionManager()
+ {
+ }
+
+ public DBChampionManager(LolContext context)
+ {
+ this.context = context;
+ }
+
+ async Task IGenericDataManager.AddItem(Champion? item)
+ {
+ if(item == null)
+ {
+ return null;
+ }
+ var additem = await context.AddAsync(item);
+ await context.SaveChangesAsync();
+ return additem.Entity;
+ }
+
+ async Task IGenericDataManager.DeleteItem(Champion? item)
+ {
+ if(item == null)
+ {
+ return false;
+ }
+ context.Remove(item);
+ await context.SaveChangesAsync();
+ return true;
+ }
+
+ async Task> IGenericDataManager.GetItems(int index, int count, string? orderingPropertyName, bool descending)
+ {
+ IEnumerable champions = context.Champions.Skip(index * count)
+ .Take(count)
+ .OrderBy(champions => orderingPropertyName)
+ .Select(champions => champions.toModel());
+ return champions;
+ }
+
+ Task> IChampionsManager.GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName, bool descending)
+ {
+ throw new NotImplementedException();
+ }
+
+ Task> IChampionsManager.GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName, bool descending)
+ {
+ throw new NotImplementedException();
+ }
+
+ Task> IGenericDataManager.GetItemsByName(string substring, int index, int count, string? orderingPropertyName, bool descending)
+ {
+ throw new NotImplementedException();
+ }
+
+ Task> IChampionsManager.GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName, bool descending)
+ {
+ throw new NotImplementedException();
+ }
+
+ Task> IChampionsManager.GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName, bool descending)
+ {
+ throw new NotImplementedException();
+ }
+
+ Task> IChampionsManager.GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName, bool descending)
+ {
+ throw new NotImplementedException();
+ }
+
+ Task IGenericDataManager.GetNbItems()
+ {
+ throw new NotImplementedException();
+ }
+
+ Task IChampionsManager.GetNbItemsByCharacteristic(string charName)
+ {
+ throw new NotImplementedException();
+ }
+
+ Task IChampionsManager.GetNbItemsByClass(ChampionClass championClass)
+ {
+ throw new NotImplementedException();
+ }
+
+ Task IGenericDataManager.GetNbItemsByName(string substring)
+ {
+ throw new NotImplementedException();
+ }
+
+ Task IChampionsManager.GetNbItemsByRunePage(RunePage? runePage)
+ {
+ throw new NotImplementedException();
+ }
+
+ Task IChampionsManager.GetNbItemsBySkill(Skill? skill)
+ {
+ throw new NotImplementedException();
+ }
+
+ Task IChampionsManager.GetNbItemsBySkill(string skill)
+ {
+ throw new NotImplementedException();
+ }
+
+ Task IGenericDataManager.UpdateItem(Champion? oldItem, Champion? newItem)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/Sources/EntityFrameworkLib/DbDataManager.cs b/Sources/EntityFrameworkLib/DbDataManager.cs
new file mode 100644
index 0000000..4149a8b
--- /dev/null
+++ b/Sources/EntityFrameworkLib/DbDataManager.cs
@@ -0,0 +1,21 @@
+using Model;
+using Shared;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EntityFrameworkLib
+{
+ public class DBDataManager : IDataManager
+ {
+ public IChampionsManager ChampionsManager => new DBChampionManager();
+
+ public ISkinsManager SkinsManager => throw new NotImplementedException();
+
+ public IRunesManager RunesManager=> throw new NotImplementedException();
+
+ public IRunePagesManager RunePagesManager=> throw new NotImplementedException();
+ }
+}
diff --git a/Sources/EntityFrameworkLib/EntityFrameworkLib.csproj b/Sources/EntityFrameworkLib/EntityFrameworkLib.csproj
index 35f51dd..4661632 100644
--- a/Sources/EntityFrameworkLib/EntityFrameworkLib.csproj
+++ b/Sources/EntityFrameworkLib/EntityFrameworkLib.csproj
@@ -20,5 +20,10 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
diff --git a/Sources/EntityFrameworkLib/ChampionContext.cs b/Sources/EntityFrameworkLib/LolContext.cs
similarity index 75%
rename from Sources/EntityFrameworkLib/ChampionContext.cs
rename to Sources/EntityFrameworkLib/LolContext.cs
index b79e71c..1afa49d 100644
--- a/Sources/EntityFrameworkLib/ChampionContext.cs
+++ b/Sources/EntityFrameworkLib/LolContext.cs
@@ -4,12 +4,12 @@ using Microsoft.EntityFrameworkCore;
namespace EntityFrameworkLib
{
- public class ChampionContext : DbContext
+ public class LolContext : DbContext
{
public DbSet Champions { get; set; }
- public ChampionContext () { }
- public ChampionContext(DbContextOptions options)
+ public LolContext () { }
+ public LolContext(DbContextOptions options)
: base(options) { }
protected override void OnConfiguring(DbContextOptionsBuilder options)
diff --git a/Sources/EntityFrameworkLib/Mappers/ChampionChanger.cs b/Sources/EntityFrameworkLib/Mappers/ChampionChanger.cs
new file mode 100644
index 0000000..a5b3f32
--- /dev/null
+++ b/Sources/EntityFrameworkLib/Mappers/ChampionChanger.cs
@@ -0,0 +1,29 @@
+using Model;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EntityFrameworkLib.Mappers
+{
+ public static class ChampionChanger
+ {
+ public static Champion toModel(this ChampionEntity championEntity)
+ {
+ return new Champion(championEntity.Name, championEntity.Bio, championEntity.Icon, championEntity.Image, championEntity.Class);
+ }
+
+ public static ChampionEntity toEntity(this Champion champion)
+ {
+ return new ChampionEntity
+ {
+ Name = champion.Name,
+ Bio = champion.Bio,
+ Icon = champion.Icon,
+ Image = champion.Image,
+ Class = champion.Class,
+ };
+ }
+ }
+}
diff --git a/Sources/EntityFrameworkLib/Migrations/20230201082358_myFirstMigration.Designer.cs b/Sources/EntityFrameworkLib/Migrations/20230201082358_myFirstMigration.Designer.cs
index 37a9bd2..ec3f117 100644
--- a/Sources/EntityFrameworkLib/Migrations/20230201082358_myFirstMigration.Designer.cs
+++ b/Sources/EntityFrameworkLib/Migrations/20230201082358_myFirstMigration.Designer.cs
@@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace EntityFrameworkLib.Migrations
{
- [DbContext(typeof(ChampionContext))]
+ [DbContext(typeof(LolContext))]
[Migration("20230201082358_myFirstMigration")]
partial class myFirstMigration
{
diff --git a/Sources/EntityFrameworkLib/Migrations/20230201084126_projet_SQLite.Designer.cs b/Sources/EntityFrameworkLib/Migrations/20230201084126_projet_SQLite.Designer.cs
index f81e67f..267bc82 100644
--- a/Sources/EntityFrameworkLib/Migrations/20230201084126_projet_SQLite.Designer.cs
+++ b/Sources/EntityFrameworkLib/Migrations/20230201084126_projet_SQLite.Designer.cs
@@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace EntityFrameworkLib.Migrations
{
- [DbContext(typeof(ChampionContext))]
+ [DbContext(typeof(LolContext))]
[Migration("20230201084126_projet_SQLite")]
partial class projetSQLite
{
diff --git a/Sources/EntityFrameworkLib/Migrations/20230201103421_migration_projet.Designer.cs b/Sources/EntityFrameworkLib/Migrations/20230201103421_migration_projet.Designer.cs
new file mode 100644
index 0000000..aa7615e
--- /dev/null
+++ b/Sources/EntityFrameworkLib/Migrations/20230201103421_migration_projet.Designer.cs
@@ -0,0 +1,47 @@
+//
+using EntityFrameworkLib;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace EntityFrameworkLib.Migrations
+{
+ [DbContext(typeof(LolContext))]
+ [Migration("20230201103421_migration_projet")]
+ partial class migrationprojet
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
+
+ modelBuilder.Entity("EntityFrameworkLib.ChampionEntity", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("Bio")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Icon")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.ToTable("Champions");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/Sources/EntityFrameworkLib/Migrations/20230201103421_migration_projet.cs b/Sources/EntityFrameworkLib/Migrations/20230201103421_migration_projet.cs
new file mode 100644
index 0000000..6f871ae
--- /dev/null
+++ b/Sources/EntityFrameworkLib/Migrations/20230201103421_migration_projet.cs
@@ -0,0 +1,22 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace EntityFrameworkLib.Migrations
+{
+ ///
+ public partial class migrationprojet : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+
+ }
+ }
+}
diff --git a/Sources/EntityFrameworkLib/Migrations/ChampionContextModelSnapshot.cs b/Sources/EntityFrameworkLib/Migrations/ChampionContextModelSnapshot.cs
index 1404409..f6b76d8 100644
--- a/Sources/EntityFrameworkLib/Migrations/ChampionContextModelSnapshot.cs
+++ b/Sources/EntityFrameworkLib/Migrations/ChampionContextModelSnapshot.cs
@@ -8,7 +8,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace EntityFrameworkLib.Migrations
{
- [DbContext(typeof(ChampionContext))]
+ [DbContext(typeof(LolContext))]
partial class ChampionContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
diff --git a/Sources/EntityFrameworkLib/Properties/launchSettings.json b/Sources/EntityFrameworkLib/Properties/launchSettings.json
new file mode 100644
index 0000000..d6cefb1
--- /dev/null
+++ b/Sources/EntityFrameworkLib/Properties/launchSettings.json
@@ -0,0 +1,12 @@
+{
+ "profiles": {
+ "EntityFrameworkLib": {
+ "commandName": "Project",
+ "launchBrowser": true,
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ },
+ "applicationUrl": "https://localhost:63785;http://localhost:63791"
+ }
+ }
+}
\ No newline at end of file
diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln
index b651117..98e1c84 100644
--- a/Sources/LeagueOfLegends.sln
+++ b/Sources/LeagueOfLegends.sln
@@ -15,7 +15,21 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Stub", "Stub", "{2C607793-B
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubLib", "StubLib\StubLib.csproj", "{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkLib", "EntityFrameworkLib\EntityFrameworkLib.csproj", "{46FBEB1B-700D-4990-A8FC-41B044014A59}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFrameworkLib", "EntityFrameworkLib\EntityFrameworkLib.csproj", "{46FBEB1B-700D-4990-A8FC-41B044014A59}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleDbSQLite", "ConsoleDbSQLite\ConsoleDbSQLite.csproj", "{F26BD4B5-BC8D-4773-98F3-FB55A6B57DEE}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTestsSQLiteInMemory", "UnitTestsSQLiteInMemory\UnitTestsSQLiteInMemory.csproj", "{2AE5C2DD-6EE1-4115-803B-963B25A5D0F5}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Consommation", "Consommation", "{F18B03EC-963B-4EEA-842D-5C041A931D20}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Web_Api", "Web_Api\Web_Api.csproj", "{B9D905BB-F4CD-4CE4-B718-7534AE5C3862}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleAPI", "ConsoleAPI\ConsoleAPI.csproj", "{313DC068-AFD4-4FCC-BB19-F344F996050D}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DBWithStub", "DBWithStub", "{F0711CE6-C48B-4E96-8DE0-79BDBB4635D6}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DBEntitiesWithStub", "DBEntitiesWithStub\DBEntitiesWithStub.csproj", "{C9D40527-6F42-4FA9-8063-554D2A0E9161}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -43,6 +57,26 @@ Global
{46FBEB1B-700D-4990-A8FC-41B044014A59}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46FBEB1B-700D-4990-A8FC-41B044014A59}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46FBEB1B-700D-4990-A8FC-41B044014A59}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F26BD4B5-BC8D-4773-98F3-FB55A6B57DEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F26BD4B5-BC8D-4773-98F3-FB55A6B57DEE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F26BD4B5-BC8D-4773-98F3-FB55A6B57DEE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F26BD4B5-BC8D-4773-98F3-FB55A6B57DEE}.Release|Any CPU.Build.0 = Release|Any CPU
+ {2AE5C2DD-6EE1-4115-803B-963B25A5D0F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {2AE5C2DD-6EE1-4115-803B-963B25A5D0F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {2AE5C2DD-6EE1-4115-803B-963B25A5D0F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {2AE5C2DD-6EE1-4115-803B-963B25A5D0F5}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B9D905BB-F4CD-4CE4-B718-7534AE5C3862}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B9D905BB-F4CD-4CE4-B718-7534AE5C3862}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B9D905BB-F4CD-4CE4-B718-7534AE5C3862}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B9D905BB-F4CD-4CE4-B718-7534AE5C3862}.Release|Any CPU.Build.0 = Release|Any CPU
+ {313DC068-AFD4-4FCC-BB19-F344F996050D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {313DC068-AFD4-4FCC-BB19-F344F996050D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {313DC068-AFD4-4FCC-BB19-F344F996050D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {313DC068-AFD4-4FCC-BB19-F344F996050D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C9D40527-6F42-4FA9-8063-554D2A0E9161}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C9D40527-6F42-4FA9-8063-554D2A0E9161}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C9D40527-6F42-4FA9-8063-554D2A0E9161}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C9D40527-6F42-4FA9-8063-554D2A0E9161}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -50,6 +84,11 @@ Global
GlobalSection(NestedProjects) = preSolution
{1889FA6E-B7C6-416E-8628-9449FB9070B9} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}
{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {2C607793-B163-4731-A4D1-AFE8A7C4C170}
+ {F26BD4B5-BC8D-4773-98F3-FB55A6B57DEE} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}
+ {2AE5C2DD-6EE1-4115-803B-963B25A5D0F5} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}
+ {B9D905BB-F4CD-4CE4-B718-7534AE5C3862} = {F18B03EC-963B-4EEA-842D-5C041A931D20}
+ {313DC068-AFD4-4FCC-BB19-F344F996050D} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}
+ {C9D40527-6F42-4FA9-8063-554D2A0E9161} = {F0711CE6-C48B-4E96-8DE0-79BDBB4635D6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9}
diff --git a/Sources/Model/Champion.cs b/Sources/Model/Champion.cs
index b8b369b..122f595 100644
--- a/Sources/Model/Champion.cs
+++ b/Sources/Model/Champion.cs
@@ -6,6 +6,10 @@ using System.Text;
namespace Model;
public class Champion : IEquatable
{
+ public int Id
+ {
+ get => Id;
+ }
public string Name
{
get => name;
@@ -53,6 +57,15 @@ public class Champion : IEquatable
Skins = new ReadOnlyCollection(skins);
}
+ public Champion(string name, string bio, string icon, LargeImage image, ChampionClass @class)
+ {
+ Name = name;
+ Bio = bio;
+ Icon = icon;
+ Image = image;
+ Class = @class;
+ }
+
public ReadOnlyCollection Skins { get; private set; }
private List skins = new ();
@@ -146,6 +159,6 @@ public class Champion : IEquatable
}
}
return sb.ToString();
- }
+ }
}
diff --git a/Sources/Model/Properties/launchSettings.json b/Sources/Model/Properties/launchSettings.json
new file mode 100644
index 0000000..b56e68f
--- /dev/null
+++ b/Sources/Model/Properties/launchSettings.json
@@ -0,0 +1,12 @@
+{
+ "profiles": {
+ "Model": {
+ "commandName": "Project",
+ "launchBrowser": true,
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ },
+ "applicationUrl": "https://localhost:63789;http://localhost:63792"
+ }
+ }
+}
\ No newline at end of file
diff --git a/Sources/Model/Rune.cs b/Sources/Model/Rune.cs
index 7b5047b..f63ad1c 100644
--- a/Sources/Model/Rune.cs
+++ b/Sources/Model/Rune.cs
@@ -48,6 +48,12 @@ namespace Model
Description = description;
}
+ public Rune(string name, string description)
+ {
+ this.name = name;
+ this.description = description;
+ }
+
public override bool Equals(object? obj)
{
if(ReferenceEquals(obj, null)) return false;
diff --git a/Sources/Model/Skin.cs b/Sources/Model/Skin.cs
index 2d8fb78..04aa838 100644
--- a/Sources/Model/Skin.cs
+++ b/Sources/Model/Skin.cs
@@ -62,6 +62,13 @@ namespace Model
Description = description;
}
+ public Skin(string name, string description, float price)
+ {
+ this.name = name;
+ this.description = description;
+ Price = price;
+ }
+
public override bool Equals(object? obj)
{
if(ReferenceEquals(obj, null)) return false;
@@ -76,7 +83,7 @@ namespace Model
public override int GetHashCode()
=> Name.GetHashCode() % 997;
- public override string ToString()
+ public override string ToString()
=> $"{Name}";
}
}
diff --git a/Sources/Shared/Properties/launchSettings.json b/Sources/Shared/Properties/launchSettings.json
new file mode 100644
index 0000000..f170bf6
--- /dev/null
+++ b/Sources/Shared/Properties/launchSettings.json
@@ -0,0 +1,12 @@
+{
+ "profiles": {
+ "Shared": {
+ "commandName": "Project",
+ "launchBrowser": true,
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ },
+ "applicationUrl": "https://localhost:63788;http://localhost:63793"
+ }
+ }
+}
\ No newline at end of file
diff --git a/Sources/StubLib/Properties/launchSettings.json b/Sources/StubLib/Properties/launchSettings.json
new file mode 100644
index 0000000..fd3fa2a
--- /dev/null
+++ b/Sources/StubLib/Properties/launchSettings.json
@@ -0,0 +1,12 @@
+{
+ "profiles": {
+ "StubLib": {
+ "commandName": "Project",
+ "launchBrowser": true,
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ },
+ "applicationUrl": "https://localhost:63790;http://localhost:63794"
+ }
+ }
+}
\ No newline at end of file
diff --git a/Sources/EntityFrameworkLib/Class1.cs b/Sources/Test/Class1.cs
similarity index 54%
rename from Sources/EntityFrameworkLib/Class1.cs
rename to Sources/Test/Class1.cs
index da896a4..5f811a3 100644
--- a/Sources/EntityFrameworkLib/Class1.cs
+++ b/Sources/Test/Class1.cs
@@ -1,7 +1,8 @@
-namespace EntityFrameworkLib
+using System;
+
+namespace Test
{
public class Class1
{
-
}
-}
\ No newline at end of file
+}
diff --git a/Sources/Test/Test.csproj b/Sources/Test/Test.csproj
new file mode 100644
index 0000000..9a7c06f
--- /dev/null
+++ b/Sources/Test/Test.csproj
@@ -0,0 +1,9 @@
+
+
+
+ net6.0-windows
+ enable
+ true
+
+
+
diff --git a/Sources/Tests/ConsoleTests/Properties/launchSettings.json b/Sources/Tests/ConsoleTests/Properties/launchSettings.json
new file mode 100644
index 0000000..6f869f3
--- /dev/null
+++ b/Sources/Tests/ConsoleTests/Properties/launchSettings.json
@@ -0,0 +1,12 @@
+{
+ "profiles": {
+ "ConsoleTests": {
+ "commandName": "Project",
+ "launchBrowser": true,
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ },
+ "applicationUrl": "https://localhost:63786;http://localhost:63796"
+ }
+ }
+}
\ No newline at end of file
diff --git a/Sources/UnitTestsSQLiteInMemory/ChampionsDbTests.cs b/Sources/UnitTestsSQLiteInMemory/ChampionsDbTests.cs
new file mode 100644
index 0000000..b47022e
--- /dev/null
+++ b/Sources/UnitTestsSQLiteInMemory/ChampionsDbTests.cs
@@ -0,0 +1,93 @@
+using EntityFrameworkLib;
+using Microsoft.Data.Sqlite;
+using Microsoft.EntityFrameworkCore;
+using Model;
+
+namespace UnitTestsSQLiteInMemory
+{
+ public class ChampionsDbTests
+ {
+ [Fact]
+ public void Add_Champions_Test()
+ {
+ //connection must be opened to use In-memory database
+ var connection = new SqliteConnection("DataSource=:memory:");
+ connection.Open();
+
+ var options = new DbContextOptionsBuilder()
+ .UseInMemoryDatabase(databaseName: "TestChampions_database")
+ .Options;
+
+ using(var context = new LolContext(options))
+ {
+ ChampionEntity akali = new ChampionEntity { Name = "Akali", Bio = "Bio Akali", Icon = "Icon Akali" };
+ ChampionEntity alistar = new ChampionEntity { Name = "Alistar", Bio = "Bio Alistar", Icon = "Icon Alistar" };
+ ChampionEntity bard = new ChampionEntity { Name = "Bard", Bio = "Bio Bard", Icon = "Icon Bard" };
+
+ context.Champions.Add(akali);
+ context.Champions.Add(alistar);
+ context.Champions.Add(bard);
+ context.SaveChanges();
+ }
+
+ using(var context = new LolContext(options))
+ {
+ Assert.Equal(3, context.Champions.Count());
+ Assert.Equal("Akali", context.Champions.First().Name);
+ }
+ }
+
+ [Fact]
+ public void Modify_Champions_Test()
+ {
+ //connection must be opened to use In-memory database
+ var connection = new SqliteConnection("DataSource=:memory:");
+ connection.Open();
+
+ var options = new DbContextOptionsBuilder()
+ .UseSqlite(connection)
+ .Options;
+
+ //prepares the database with one instance of the context
+ using (var context = new LolContext(options))
+ {
+ //context.Database.OpenConnection();
+ context.Database.EnsureCreated();
+
+ ChampionEntity akali = new ChampionEntity { Name = "Akali", Bio = "Bio Akali", Icon = "Icon Akali" };
+ ChampionEntity akshan = new ChampionEntity { Name = "Akshan", Bio = "Bio Akshan", Icon = "Icon Akshan" };
+ ChampionEntity twitch = new ChampionEntity { Name = "Twitch", Bio = "Bio Twitch", Icon = "icon Twitch" };
+
+ context.Champions.Add(akali);
+ context.Champions.Add(akshan);
+ context.Champions.Add(twitch);
+ context.SaveChanges();
+ }
+
+ //uses another instance of the context to do the tests
+ using (var context = new LolContext(options))
+ {
+ context.Database.EnsureCreated();
+
+ string nameToFind = "ak";
+ Assert.Equal(2, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
+ nameToFind = "wi";
+ Assert.Equal(1, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
+ var akshan = context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).First();
+ akshan.Name = "Volibear";
+ context.SaveChanges();
+ }
+
+ //uses another instance of the context to do the tests
+ using (var context = new LolContext(options))
+ {
+ context.Database.EnsureCreated();
+
+ string nameToFind = "i";
+ Assert.Equal(2, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
+ nameToFind = "voli";
+ Assert.Equal(1, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Sources/UnitTestsSQLiteInMemory/UnitTestsSQLiteInMemory.csproj b/Sources/UnitTestsSQLiteInMemory/UnitTestsSQLiteInMemory.csproj
new file mode 100644
index 0000000..a1be2d9
--- /dev/null
+++ b/Sources/UnitTestsSQLiteInMemory/UnitTestsSQLiteInMemory.csproj
@@ -0,0 +1,30 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+ false
+
+
+
+
+
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
+
+
+
+
+
+
+
diff --git a/Sources/UnitTestsSQLiteInMemory/Usings.cs b/Sources/UnitTestsSQLiteInMemory/Usings.cs
new file mode 100644
index 0000000..8c927eb
--- /dev/null
+++ b/Sources/UnitTestsSQLiteInMemory/Usings.cs
@@ -0,0 +1 @@
+global using Xunit;
\ No newline at end of file
diff --git a/Sources/Web_Api/ChampionDTO.cs b/Sources/Web_Api/ChampionDTO.cs
new file mode 100644
index 0000000..722784d
--- /dev/null
+++ b/Sources/Web_Api/ChampionDTO.cs
@@ -0,0 +1,16 @@
+using Model;
+
+namespace Web_Api
+{
+ public class ChampionDTO
+ {
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public string Bio { get; set; }
+
+ public Champion toModel()
+ {
+ return new Champion(Name, Bio);
+ }
+ }
+}
diff --git a/Sources/Web_Api/Controllers/ChampionsController.cs b/Sources/Web_Api/Controllers/ChampionsController.cs
new file mode 100644
index 0000000..f911511
--- /dev/null
+++ b/Sources/Web_Api/Controllers/ChampionsController.cs
@@ -0,0 +1,163 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.SignalR;
+using Model;
+using StubLib;
+using Web_Api.Mapper;
+
+namespace Web_Api.Controllers
+{
+ [ApiController]
+ [Route("api/[controller]")]
+ public class ChampionsController : Controller
+ {
+ private StubData.ChampionsManager ChampionsManager { get; set; } = new StubData.ChampionsManager(new StubData());
+
+ private readonly ILogger _logger;
+
+ public ChampionsController(ILogger logger)
+ {
+ _logger = logger;
+ }
+
+ [HttpGet]
+ public async Task Get()
+ {
+ var list = await ChampionsManager.GetItems(0, await ChampionsManager.GetNbItems());
+ return Ok(list.Select(champion => champion?.toDTO()));
+ }
+
+ [HttpGet("name")]
+ public async Task GetById(string name)
+ {
+ var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);
+ return Ok(championSelected.Select(c => c?.toDTO()));
+ }
+
+ [HttpPost("addChampion")]
+ public async Task AddChampion(ChampionDTO champion)
+ {
+ var newChampion = champion.toModel();
+ await ChampionsManager.AddItem(newChampion);
+ if(champion.Bio == "string")
+ {
+ champion.Bio = "Aucune bio";
+ }
+ Console.WriteLine("Le champion { " + champion.Name + " } avec pour bio { " + champion.Bio + " } a bien été ajouté");
+ return Ok();
+ }
+
+ [HttpPut("updateChampion")]
+ public async Task UpdateChampion(string name, ChampionDTO champion)
+ {
+ var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);
+ var existingChampion = championSelected.FirstOrDefault();
+ if (existingChampion == null)
+ {
+ Console.WriteLine("Le champion { " + name + " } n'existe pas !");
+ return NotFound();
+ }
+ var updatedChampion = champion.toModel();
+ await ChampionsManager.UpdateItem(existingChampion, updatedChampion);
+ if(updatedChampion.Bio == "string")
+ {
+ updatedChampion.Bio = "Aucune bio";
+ }
+ Console.WriteLine("Le champion { " + name + " } a été modifié en { " + updatedChampion.Name + " } avec pour bio { " + updatedChampion.Bio + " }");
+ return Ok();
+ }
+
+ [HttpDelete("deleteChampion")]
+ public async Task DeleteChampion(string name)
+ {
+ var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);
+ if(!await ChampionsManager.DeleteItem(championSelected.FirstOrDefault()))
+ {
+ Console.WriteLine("champion { " + name + " } non trouvé !");
+ return NotFound();
+ }
+ Console.WriteLine("champion { " + name + " } supprimé");
+ return Ok();
+ }
+
+ /*[HttpGet(Name = "GetChampionsById")]
+ public async Task GetById()
+ {
+
+ }*/
+ /*// GET: ChampionsController
+ public ActionResult Index()
+ {
+ return View();
+ }
+
+ // GET: ChampionsController/Details/5
+ public ActionResult Details(int id)
+ {
+ return View();
+ }
+
+ // GET: ChampionsController/Create
+ public ActionResult Create()
+ {
+ return View();
+ }
+
+ // POST: ChampionsController/Create
+ [HttpPost]
+ [ValidateAntiForgeryToken]
+ public ActionResult Create(IFormCollection collection)
+ {
+ try
+ {
+ return RedirectToAction(nameof(Index));
+ }
+ catch
+ {
+ return View();
+ }
+ }
+
+ // GET: ChampionsController/Edit/5
+ public ActionResult Edit(int id)
+ {
+ return View();
+ }
+
+ // POST: ChampionsController/Edit/5
+ [HttpPost]
+ [ValidateAntiForgeryToken]
+ public ActionResult Edit(int id, IFormCollection collection)
+ {
+ try
+ {
+ return RedirectToAction(nameof(Index));
+ }
+ catch
+ {
+ return View();
+ }
+ }
+
+ // GET: ChampionsController/Delete/5
+ public ActionResult Delete(int id)
+ {
+ return View();
+ }
+
+ // POST: ChampionsController/Delete/5
+ [HttpPost]
+ [ValidateAntiForgeryToken]
+ public ActionResult Delete(int id, IFormCollection collection)
+ {
+ try
+ {
+ return RedirectToAction(nameof(Index));
+ }
+ catch
+ {
+ return View();
+ }
+ }*/
+ }
+}
diff --git a/Sources/Web_Api/Controllers/RunesController.cs b/Sources/Web_Api/Controllers/RunesController.cs
new file mode 100644
index 0000000..f8df9a0
--- /dev/null
+++ b/Sources/Web_Api/Controllers/RunesController.cs
@@ -0,0 +1,156 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using StubLib;
+using Web_Api.Mapper;
+using static StubLib.StubData;
+
+namespace Web_Api.Controllers
+{
+ [ApiController]
+ [Route("api/[controller]")]
+ public class RunesController : Controller
+ {
+ private StubData.RunesManager RunesManager { get; set; } = new StubData.RunesManager(new StubData());
+
+ private readonly ILogger _logger;
+
+ public RunesController(ILogger logger)
+ {
+ _logger = logger;
+ }
+
+ [HttpGet]
+ public async Task Get()
+ {
+ var list = await RunesManager.GetItems(0, await RunesManager.GetNbItems());
+ return Ok(list.Select(rune => rune?.toDTO()));
+ }
+
+ [HttpGet("name")]
+ public async Task GetById(string name)
+ {
+ var runeSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null);
+ return Ok(runeSelected.Select(rune => rune?.toDTO()));
+ }
+
+ [HttpPost("addRune")]
+ public async Task AddRune(RuneDTO rune)
+ {
+ var newRune = rune.toModel();
+ await RunesManager.AddItem(newRune);
+ if(rune.Description == "string")
+ {
+ rune.Description = "Aucune bio";
+ }
+ Console.WriteLine("La rune { " + rune.Name + " } avec pour descrption { " + rune.Description + " } a bien été ajoutée");
+ return Ok(newRune);
+ }
+
+ [HttpPut("updateRune")]
+ public async Task UpdateRune(string name, RuneDTO rune)
+ {
+ var runeSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null);
+ var existingRune = runeSelected.FirstOrDefault();
+ if (existingRune == null)
+ {
+ Console.WriteLine("La rune { " + name + " } n'existe pas !");
+ return NotFound();
+ }
+ var updatedRune = rune.toModel();
+ await RunesManager.UpdateItem(existingRune, updatedRune);
+ if (rune.Description == "string")
+ {
+ rune.Description = "Aucune bio";
+ }
+ Console.WriteLine("La rune { " + name + " } a été modifiée en { " + updatedRune.Name + " } avec pour description { " + rune.Description + " }");
+ return Ok();
+ }
+
+ [HttpDelete("deleteRune")]
+ public async Task DeleteRune(string name)
+ {
+ var runeSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null);
+ if(!await RunesManager.DeleteItem(runeSelected.FirstOrDefault()))
+ {
+ Console.WriteLine("rune { " + name + " } non trouvée !");
+ return NotFound();
+ }
+ Console.WriteLine("rune { " + name + " } supprimée");
+ return Ok();
+ }
+ /*// GET: RuneController
+ public ActionResult Index()
+ {
+ return View();
+ }
+
+ // GET: RuneController/Details/5
+ public ActionResult Details(int id)
+ {
+ return View();
+ }
+
+ // GET: RuneController/Create
+ public ActionResult Create()
+ {
+ return View();
+ }
+
+ // POST: RuneController/Create
+ [HttpPost]
+ [ValidateAntiForgeryToken]
+ public ActionResult Create(IFormCollection collection)
+ {
+ try
+ {
+ return RedirectToAction(nameof(Index));
+ }
+ catch
+ {
+ return View();
+ }
+ }
+
+ // GET: RuneController/Edit/5
+ public ActionResult Edit(int id)
+ {
+ return View();
+ }
+
+ // POST: RuneController/Edit/5
+ [HttpPost]
+ [ValidateAntiForgeryToken]
+ public ActionResult Edit(int id, IFormCollection collection)
+ {
+ try
+ {
+ return RedirectToAction(nameof(Index));
+ }
+ catch
+ {
+ return View();
+ }
+ }
+
+ // GET: RuneController/Delete/5
+ public ActionResult Delete(int id)
+ {
+ return View();
+ }
+
+ // POST: RuneController/Delete/5
+ [HttpPost]
+ [ValidateAntiForgeryToken]
+ public ActionResult Delete(int id, IFormCollection collection)
+ {
+ try
+ {
+ return RedirectToAction(nameof(Index));
+ }
+ catch
+ {
+ return View();
+ }
+ }*/
+ }
+}
diff --git a/Sources/Web_Api/Controllers/SkinsController.cs b/Sources/Web_Api/Controllers/SkinsController.cs
new file mode 100644
index 0000000..c6d4bb1
--- /dev/null
+++ b/Sources/Web_Api/Controllers/SkinsController.cs
@@ -0,0 +1,155 @@
+using Microsoft.AspNetCore.Mvc;
+using StubLib;
+using Web_Api.Mapper;
+
+namespace Web_Api.Controllers
+{
+ [ApiController]
+ [Route("api/[controller]")]
+ public class SkinsController : Controller
+ {
+ private StubData.SkinsManager SkinsManager { get; set; } = new StubData.SkinsManager(new StubData());
+
+ private readonly ILogger _logger;
+
+ public SkinsController(ILogger logger)
+ {
+ _logger = logger;
+ }
+
+ [HttpGet]
+ public async Task Get()
+ {
+ var list = await SkinsManager.GetItems(0, await SkinsManager.GetNbItems());
+ return Ok(list.Select(skin => skin?.toDTO()));
+ }
+
+ [HttpGet("name")]
+ public async Task GetById(string name)
+ {
+ var skinSelected = await SkinsManager.GetItemsByName(name, 0, await SkinsManager.GetNbItemsByName(name), null);
+ return Ok(skinSelected.Select(skin => skin?.toDTO()));
+ }
+
+ [HttpPost("addSkin")]
+ public async Task AddSkin(SkinDTO skin)
+ {
+ var newSkin = skin.toModel();
+ await SkinsManager.AddItem(newSkin);
+ if(skin.Description == "string")
+ {
+ skin.Description = "Aucune bio";
+ }
+ Console.WriteLine("Le skin { " + skin.Name + " } avec pour description { " + skin.Description + " } a bien été ajouté");
+ return Ok(newSkin);
+ }
+
+ [HttpPut("updateSkin")]
+ public async Task UpdateChampion(string name, SkinDTO skin)
+ {
+ var skinSelected = await SkinsManager.GetItemsByName(name, 0, await SkinsManager.GetNbItemsByName(name), null);
+ var existingSkin = skinSelected.FirstOrDefault();
+ if(existingSkin == null)
+ {
+ Console.WriteLine("Le skin { " + name + " } n'existe pas !");
+ return NotFound();
+ }
+
+ var updatedSkin = skin.toModel();
+ await SkinsManager.UpdateItem(existingSkin, updatedSkin);
+ if(skin.Description == "string")
+ {
+ skin.Description = "Aucune bio";
+ }
+ Console.WriteLine("Le skin { " + name + " } a été modifié en " + " { " + updatedSkin.Name + " } avec pour description { " + updatedSkin.Description + " }<");
+ return Ok();
+ }
+
+ [HttpDelete("deleteSkin")]
+ public async Task DeleteChampion(string name)
+ {
+ var skinSelected = await SkinsManager.GetItemsByName(name, 0, await SkinsManager.GetNbItemsByName(name), null);
+ if (!await SkinsManager.DeleteItem(skinSelected.FirstOrDefault()))
+ {
+ Console.WriteLine("skin { " + name + " } non trouvé !");
+ return NotFound();
+ }
+ Console.WriteLine("skin { " + name + " } supprimé");
+ return Ok();
+ }
+ /*// GET: SkinsController
+ public ActionResult Index()
+ {
+ return View();
+ }
+
+ // GET: SkinsController/Details/5
+ public ActionResult Details(int id)
+ {
+ return View();
+ }
+
+ // GET: SkinsController/Create
+ public ActionResult Create()
+ {
+ return View();
+ }
+
+ // POST: SkinsController/Create
+ [HttpPost]
+ [ValidateAntiForgeryToken]
+ public ActionResult Create(IFormCollection collection)
+ {
+ try
+ {
+ return RedirectToAction(nameof(Index));
+ }
+ catch
+ {
+ return View();
+ }
+ }
+
+ // GET: SkinsController/Edit/5
+ public ActionResult Edit(int id)
+ {
+ return View();
+ }
+
+ // POST: SkinsController/Edit/5
+ [HttpPost]
+ [ValidateAntiForgeryToken]
+ public ActionResult Edit(int id, IFormCollection collection)
+ {
+ try
+ {
+ return RedirectToAction(nameof(Index));
+ }
+ catch
+ {
+ return View();
+ }
+ }
+
+ // GET: SkinsController/Delete/5
+ public ActionResult Delete(int id)
+ {
+ return View();
+ }
+
+ // POST: SkinsController/Delete/5
+ [HttpPost]
+ [ValidateAntiForgeryToken]
+ public ActionResult Delete(int id, IFormCollection collection)
+ {
+ try
+ {
+ return RedirectToAction(nameof(Index));
+ }
+ catch
+ {
+ return View();
+ }
+ }*/
+ }
+}
diff --git a/Sources/Web_Api/Controllers/WeatherForecastController.cs b/Sources/Web_Api/Controllers/WeatherForecastController.cs
new file mode 100644
index 0000000..de76cd4
--- /dev/null
+++ b/Sources/Web_Api/Controllers/WeatherForecastController.cs
@@ -0,0 +1,33 @@
+using Microsoft.AspNetCore.Mvc;
+
+namespace Web_Api.Controllers
+{
+ [ApiController]
+ [Route("[controller]")]
+ public class WeatherForecastController : ControllerBase
+ {
+ private static readonly string[] Summaries = new[]
+ {
+ "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
+ };
+
+ private readonly ILogger _logger;
+
+ public WeatherForecastController(ILogger logger)
+ {
+ _logger = logger;
+ }
+
+ [HttpGet(Name = "GetWeatherForecast")]
+ public IEnumerable Get()
+ {
+ return Enumerable.Range(1, 5).Select(index => new WeatherForecast
+ {
+ Date = DateTime.Now.AddDays(index),
+ TemperatureC = Random.Shared.Next(-20, 55),
+ Summary = Summaries[Random.Shared.Next(Summaries.Length)]
+ })
+ .ToArray();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Sources/Web_Api/Mapper/ChampionMapper.cs b/Sources/Web_Api/Mapper/ChampionMapper.cs
new file mode 100644
index 0000000..4659056
--- /dev/null
+++ b/Sources/Web_Api/Mapper/ChampionMapper.cs
@@ -0,0 +1,17 @@
+using Model;
+using Web_Api.Controllers;
+
+namespace Web_Api.Mapper
+{
+ public static class ChampionMapper
+ {
+ public static ChampionDTO toDTO(this Champion champion)
+ {
+ return new ChampionDTO()
+ {
+ Name = champion.Name,
+ Bio = champion.Bio
+ };
+ }
+ }
+}
diff --git a/Sources/Web_Api/Mapper/RuneMapper.cs b/Sources/Web_Api/Mapper/RuneMapper.cs
new file mode 100644
index 0000000..5fadfb9
--- /dev/null
+++ b/Sources/Web_Api/Mapper/RuneMapper.cs
@@ -0,0 +1,16 @@
+using Model;
+
+namespace Web_Api.Mapper
+{
+ public static class RuneMapper
+ {
+ public static RuneDTO toDTO(this Rune rune)
+ {
+ return new RuneDTO
+ {
+ Name= rune.Name,
+ Description= rune.Description
+ };
+ }
+ }
+}
diff --git a/Sources/Web_Api/Mapper/SkinMapper.cs b/Sources/Web_Api/Mapper/SkinMapper.cs
new file mode 100644
index 0000000..5253091
--- /dev/null
+++ b/Sources/Web_Api/Mapper/SkinMapper.cs
@@ -0,0 +1,18 @@
+using Model;
+using System.Runtime.CompilerServices;
+
+namespace Web_Api.Mapper
+{
+ public static class SkinMapper
+ {
+ public static SkinDTO toDTO(this Skin skin)
+ {
+ return new SkinDTO()
+ {
+ Name = skin.Name,
+ Description = skin.Description,
+ Price = skin.Price
+ };
+ }
+ }
+}
diff --git a/Sources/Web_Api/Program.cs b/Sources/Web_Api/Program.cs
new file mode 100644
index 0000000..48863a6
--- /dev/null
+++ b/Sources/Web_Api/Program.cs
@@ -0,0 +1,25 @@
+var builder = WebApplication.CreateBuilder(args);
+
+// Add services to the container.
+
+builder.Services.AddControllers();
+// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
+builder.Services.AddEndpointsApiExplorer();
+builder.Services.AddSwaggerGen();
+
+var app = builder.Build();
+
+// Configure the HTTP request pipeline.
+if (app.Environment.IsDevelopment())
+{
+ app.UseSwagger();
+ app.UseSwaggerUI();
+}
+
+app.UseHttpsRedirection();
+
+app.UseAuthorization();
+
+app.MapControllers();
+
+app.Run();
diff --git a/Sources/Web_Api/Properties/launchSettings.json b/Sources/Web_Api/Properties/launchSettings.json
new file mode 100644
index 0000000..7d62681
--- /dev/null
+++ b/Sources/Web_Api/Properties/launchSettings.json
@@ -0,0 +1,31 @@
+{
+ "$schema": "https://json.schemastore.org/launchsettings.json",
+ "iisSettings": {
+ "windowsAuthentication": false,
+ "anonymousAuthentication": true,
+ "iisExpress": {
+ "applicationUrl": "http://localhost:43712",
+ "sslPort": 44391
+ }
+ },
+ "profiles": {
+ "Web_Api": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "launchUrl": "swagger",
+ "applicationUrl": "https://localhost:7189;http://localhost:5097",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ },
+ "IIS Express": {
+ "commandName": "IISExpress",
+ "launchBrowser": true,
+ "launchUrl": "swagger",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ }
+ }
+}
diff --git a/Sources/Web_Api/RuneDTO.cs b/Sources/Web_Api/RuneDTO.cs
new file mode 100644
index 0000000..6ff89e1
--- /dev/null
+++ b/Sources/Web_Api/RuneDTO.cs
@@ -0,0 +1,18 @@
+using Model;
+
+namespace Web_Api
+{
+ public class RuneDTO
+ {
+ public int Id { get; set; }
+
+ public string Name { get; set; }
+
+ public string Description { get; set; }
+
+ public Rune toModel()
+ {
+ return new Rune(Name, Description);
+ }
+ }
+}
diff --git a/Sources/Web_Api/SkinDTO.cs b/Sources/Web_Api/SkinDTO.cs
new file mode 100644
index 0000000..a5290ea
--- /dev/null
+++ b/Sources/Web_Api/SkinDTO.cs
@@ -0,0 +1,20 @@
+using Model;
+
+namespace Web_Api
+{
+ public class SkinDTO
+ {
+ public int Id { get; set; }
+
+ public string Name { get; set; }
+
+ public string Description { get; set; }
+
+ public float Price { get; set; }
+
+ public Skin toModel()
+ {
+ return new Skin(Name, Description, Price);
+ }
+ }
+}
diff --git a/Sources/Web_Api/WeatherForecast.cs b/Sources/Web_Api/WeatherForecast.cs
new file mode 100644
index 0000000..cf000f8
--- /dev/null
+++ b/Sources/Web_Api/WeatherForecast.cs
@@ -0,0 +1,13 @@
+namespace Web_Api
+{
+ public class WeatherForecast
+ {
+ public DateTime Date { get; set; }
+
+ public int TemperatureC { get; set; }
+
+ public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
+
+ public string? Summary { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Sources/Web_Api/Web_Api.csproj b/Sources/Web_Api/Web_Api.csproj
new file mode 100644
index 0000000..9776754
--- /dev/null
+++ b/Sources/Web_Api/Web_Api.csproj
@@ -0,0 +1,17 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Sources/Web_Api/appsettings.Development.json b/Sources/Web_Api/appsettings.Development.json
new file mode 100644
index 0000000..0c208ae
--- /dev/null
+++ b/Sources/Web_Api/appsettings.Development.json
@@ -0,0 +1,8 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ }
+}
diff --git a/Sources/Web_Api/appsettings.json b/Sources/Web_Api/appsettings.json
new file mode 100644
index 0000000..10f68b8
--- /dev/null
+++ b/Sources/Web_Api/appsettings.json
@@ -0,0 +1,9 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ },
+ "AllowedHosts": "*"
+}