From 0c02ac49f54221416218201b94923f4f323607ab Mon Sep 17 00:00:00 2001 From: Theo DUPIN Date: Sat, 25 Mar 2023 15:50:07 +0100 Subject: [PATCH] DbSet de toutes les tables dont il y a besoin --- Sources/ConsoleAPI/ConsoleAPI.csproj | 4 + Sources/ConsoleConfig/App.config | 8 + Sources/ConsoleConfig/ConsoleConfig.csproj | 15 + Sources/ConsoleConfig/Program.cs | 26 ++ .../ConsoleDbSQLite/ConsoleDbSQLite.csproj | 1 + Sources/DBDataManager/DBChampionManager.cs | 10 +- Sources/DBDataManager/DBDataManager.csproj | 4 + Sources/DBDataManager/DBSkinManager.cs | 76 ++++ Sources/DBDataManager/Extensions.cs | 18 +- .../DBEntitiesWithStub.csproj | 1 + Sources/EntityFrameworkLib/ChampionEntity.cs | 17 +- .../CharacteristicEntity.cs | 23 ++ .../EntityFrameworkLib.csproj | 1 + .../EntityFrameworkLib/EnumChampionClass.cs | 19 + .../EntityFrameworkLib/LargeImageEntity.cs | 20 ++ Sources/EntityFrameworkLib/LolContext.cs | 25 +- .../Mappers/ChampionChanger.cs | 42 ++- .../Mappers/CharacteristicChanger.cs | 30 ++ .../Mappers/LargeImageChanger.cs | 28 ++ .../Mappers/SkillChanger.cs | 33 ++ .../EntityFrameworkLib/Mappers/SkinChanger.cs | 30 ++ ...0230201082358_myFirstMigration.Designer.cs | 47 --- .../20230201082358_myFirstMigration.cs | 36 -- .../20230201084126_projet_SQLite.Designer.cs | 47 --- .../20230201084126_projet_SQLite.cs | 22 -- ...0230201103421_migration_projet.Designer.cs | 47 --- .../20230201103421_migration_projet.cs | 22 -- .../20230325144614_AllMigrations.Designer.cs | 333 ++++++++++++++++++ .../20230325144614_AllMigrations.cs | 283 +++++++++++++++ .../ChampionContextModelSnapshot.cs | 44 --- .../Migrations/LolContextModelSnapshot.cs | 330 +++++++++++++++++ Sources/EntityFrameworkLib/RuneEntity.cs | 28 ++ Sources/EntityFrameworkLib/RunePageEntity.cs | 19 + .../EntityFrameworkLib/RunePageRuneEntity.cs | 24 ++ Sources/EntityFrameworkLib/SkillEntity.cs | 24 ++ Sources/EntityFrameworkLib/Skin.cs | 16 - Sources/EntityFrameworkLib/SkinEntity.cs | 33 ++ .../EntityFrameworkLib/projet.Champions.db | Bin 0 -> 135168 bytes Sources/LeagueOfLegends.sln | 23 +- Sources/Model/LargeImage.cs | 7 + Sources/Model/Model.csproj | 1 + Sources/Model/RunePage.cs | 165 ++++----- Sources/Model/Skin.cs | 7 + Sources/Shared/Shared.csproj | 1 + Sources/StubLib/StubLib.csproj | 1 + .../Tests/ConsoleTests/ConsoleTests.csproj | 1 + .../ChampionsDbTests.cs | 48 ++- .../UnitTestsSQLiteInMemory.csproj | 1 + Sources/Web_Api/ChampionDTO.cs | 4 + .../Controllers/ChampionsController.cs | 40 ++- .../Web_Api/Controllers/RunesController.cs | 22 +- .../Web_Api/Controllers/SkinsController.cs | 23 +- .../Controllers/WeatherForecastController.cs | 33 -- Sources/Web_Api/LargeImageDTO.cs | 17 + Sources/Web_Api/Program.cs | 63 +++- Sources/Web_Api/SwaggerOptions.cs | 10 + Sources/Web_Api/WeatherForecast.cs | 13 - Sources/Web_Api/Web_Api.csproj | 2 + 58 files changed, 1790 insertions(+), 478 deletions(-) create mode 100644 Sources/ConsoleConfig/App.config create mode 100644 Sources/ConsoleConfig/ConsoleConfig.csproj create mode 100644 Sources/ConsoleConfig/Program.cs create mode 100644 Sources/DBDataManager/DBSkinManager.cs create mode 100644 Sources/EntityFrameworkLib/CharacteristicEntity.cs create mode 100644 Sources/EntityFrameworkLib/EnumChampionClass.cs create mode 100644 Sources/EntityFrameworkLib/LargeImageEntity.cs create mode 100644 Sources/EntityFrameworkLib/Mappers/CharacteristicChanger.cs create mode 100644 Sources/EntityFrameworkLib/Mappers/LargeImageChanger.cs create mode 100644 Sources/EntityFrameworkLib/Mappers/SkillChanger.cs create mode 100644 Sources/EntityFrameworkLib/Mappers/SkinChanger.cs delete mode 100644 Sources/EntityFrameworkLib/Migrations/20230201082358_myFirstMigration.Designer.cs delete mode 100644 Sources/EntityFrameworkLib/Migrations/20230201082358_myFirstMigration.cs delete mode 100644 Sources/EntityFrameworkLib/Migrations/20230201084126_projet_SQLite.Designer.cs delete mode 100644 Sources/EntityFrameworkLib/Migrations/20230201084126_projet_SQLite.cs delete mode 100644 Sources/EntityFrameworkLib/Migrations/20230201103421_migration_projet.Designer.cs delete mode 100644 Sources/EntityFrameworkLib/Migrations/20230201103421_migration_projet.cs create mode 100644 Sources/EntityFrameworkLib/Migrations/20230325144614_AllMigrations.Designer.cs create mode 100644 Sources/EntityFrameworkLib/Migrations/20230325144614_AllMigrations.cs delete mode 100644 Sources/EntityFrameworkLib/Migrations/ChampionContextModelSnapshot.cs create mode 100644 Sources/EntityFrameworkLib/Migrations/LolContextModelSnapshot.cs create mode 100644 Sources/EntityFrameworkLib/RuneEntity.cs create mode 100644 Sources/EntityFrameworkLib/RunePageEntity.cs create mode 100644 Sources/EntityFrameworkLib/RunePageRuneEntity.cs create mode 100644 Sources/EntityFrameworkLib/SkillEntity.cs delete mode 100644 Sources/EntityFrameworkLib/Skin.cs create mode 100644 Sources/EntityFrameworkLib/SkinEntity.cs create mode 100644 Sources/EntityFrameworkLib/projet.Champions.db delete mode 100644 Sources/Web_Api/Controllers/WeatherForecastController.cs create mode 100644 Sources/Web_Api/LargeImageDTO.cs create mode 100644 Sources/Web_Api/SwaggerOptions.cs delete mode 100644 Sources/Web_Api/WeatherForecast.cs diff --git a/Sources/ConsoleAPI/ConsoleAPI.csproj b/Sources/ConsoleAPI/ConsoleAPI.csproj index a476915..260b029 100644 --- a/Sources/ConsoleAPI/ConsoleAPI.csproj +++ b/Sources/ConsoleAPI/ConsoleAPI.csproj @@ -7,6 +7,10 @@ enable + + + + diff --git a/Sources/ConsoleConfig/App.config b/Sources/ConsoleConfig/App.config new file mode 100644 index 0000000..2cf764e --- /dev/null +++ b/Sources/ConsoleConfig/App.config @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/Sources/ConsoleConfig/ConsoleConfig.csproj b/Sources/ConsoleConfig/ConsoleConfig.csproj new file mode 100644 index 0000000..96df65b --- /dev/null +++ b/Sources/ConsoleConfig/ConsoleConfig.csproj @@ -0,0 +1,15 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + diff --git a/Sources/ConsoleConfig/Program.cs b/Sources/ConsoleConfig/Program.cs new file mode 100644 index 0000000..1dfe317 --- /dev/null +++ b/Sources/ConsoleConfig/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Configuration; +using System.Collections.Specialized; + +namespace ConsoleConfig +{ + class Program + { + static void Main(string[] args) + { + string sAttr; + + // Read a particular key from the config file + sAttr = ConfigurationManager.AppSettings.Get("Key0"); + Console.WriteLine("The value of Key0: " + sAttr); + + // Read all the keys from the config file + NameValueCollection sAll; + sAll = ConfigurationManager.AppSettings; + + foreach (string s in sAll.AllKeys) + Console.WriteLine("Key: " + s + " Value: " + sAll.Get(s)); + Console.ReadLine(); + } + } +} diff --git a/Sources/ConsoleDbSQLite/ConsoleDbSQLite.csproj b/Sources/ConsoleDbSQLite/ConsoleDbSQLite.csproj index c112e42..6ccc58d 100644 --- a/Sources/ConsoleDbSQLite/ConsoleDbSQLite.csproj +++ b/Sources/ConsoleDbSQLite/ConsoleDbSQLite.csproj @@ -9,6 +9,7 @@ + all diff --git a/Sources/DBDataManager/DBChampionManager.cs b/Sources/DBDataManager/DBChampionManager.cs index 7158518..522342e 100644 --- a/Sources/DBDataManager/DBChampionManager.cs +++ b/Sources/DBDataManager/DBChampionManager.cs @@ -47,11 +47,7 @@ namespace DBDataManager 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; + return (IEnumerable)context.Champions.GetItemsWithFilterAndOrdering(c => true, index, count, orderingPropertyName, descending); } private Func filterByCharacteristic = (champ, charName) => champ.Characteristics.Keys.Any(k => k.Contains(charName, StringComparison.InvariantCultureIgnoreCase)); @@ -126,8 +122,8 @@ namespace DBDataManager Task IGenericDataManager.UpdateItem(Champion? oldItem, Champion? newItem) { - throw new NotImplementedException(); + throw new Exception(); } - //=> context.Champions.toPocos().UpdateItem(oldItem, newItem); + //=> (IList)context.Champions.toPocos().UpdateItem(oldItem, newItem); } } diff --git a/Sources/DBDataManager/DBDataManager.csproj b/Sources/DBDataManager/DBDataManager.csproj index 47a7c34..49f43b3 100644 --- a/Sources/DBDataManager/DBDataManager.csproj +++ b/Sources/DBDataManager/DBDataManager.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/Sources/DBDataManager/DBSkinManager.cs b/Sources/DBDataManager/DBSkinManager.cs new file mode 100644 index 0000000..690750a --- /dev/null +++ b/Sources/DBDataManager/DBSkinManager.cs @@ -0,0 +1,76 @@ +using EntityFrameworkLib; +using EntityFrameworkLib.Mappers; +using Model; +using Shared; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DBDataManager +{ + public class DBSkinManager : ISkinsManager + { + private readonly LolContext context; + + public DBSkinManager() + { + } + + public DBSkinManager(LolContext context) + { + this.context = context; + } + + async Task IGenericDataManager.AddItem(Skin? item) + { + if(item == null) + { + return null; + } + var additem = await context.AddAsync(item); + await context.SaveChangesAsync(); + return additem.Entity; + } + + async Task IGenericDataManager.DeleteItem(Skin? item) + { + if(item == null) + { + return false; + } + context.Remove(item); + await context.SaveChangesAsync(); + return true; + } + + Task> IGenericDataManager.GetItems(int index, int count, string? orderingPropertyName, bool descending) + => context.Skins.toPocos().GetItemsWithFilterAndOrdering(s => true, index, count, orderingPropertyName, descending); + + private static Func filterByChampion = (skin, champion) => champion != null && skin.Champion.Equals(champion!); + + Task> ISkinsManager.GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName, bool descending) + => context.Skins.toPocos().GetItemsWithFilterAndOrdering(skin => filterByChampion(skin, champion), index, count, orderingPropertyName, descending); + + private static Func filterByName = (skin, substring) => skin.Name.Contains(substring, StringComparison.InvariantCultureIgnoreCase); + + Task> IGenericDataManager.GetItemsByName(string substring, int index, int count, string? orderingPropertyName, bool descending) + => context.Skins.toPocos().GetItemsWithFilterAndOrdering(skin => filterByName(skin, substring), index, count, orderingPropertyName, descending); + + Task IGenericDataManager.GetNbItems() + => context.Skins.GetNbItemsWithFilter(s => true); + + Task ISkinsManager.GetNbItemsByChampion(Champion? champion) + => context.Skins.toPocos().GetNbItemsWithFilter(skin => filterByChampion(skin, champion)); + + Task IGenericDataManager.GetNbItemsByName(string substring) + => context.Skins.toPocos().GetNbItemsWithFilter(skin => filterByName(skin, substring)); + + Task IGenericDataManager.UpdateItem(Skin? oldItem, Skin? newItem) + { + throw new Exception(); + } + // => (IList)context.Skins.toPocos().UpdateItem(oldItem, newItem); + } +} diff --git a/Sources/DBDataManager/Extensions.cs b/Sources/DBDataManager/Extensions.cs index ef92821..34f7548 100644 --- a/Sources/DBDataManager/Extensions.cs +++ b/Sources/DBDataManager/Extensions.cs @@ -38,23 +38,33 @@ namespace DBDataManager return result; } + public static IEnumerable toPocos(this IEnumerable skins) + { + List result = new List(); + foreach(SkinEntity skin in skins) + { + result.Add(skin.toModel()); + } + return result; + } + internal static Task GetNbItemsWithFilter(this IEnumerable collection, Func filter) { return Task.FromResult(collection.Count(item => filter(item))); } - internal static Task UpdateItem(this IList collection, T? oldItem, T? newItem) + internal static Task UpdateItem(this IList collection, Champion? oldItem, Champion? newItem) { - if (oldItem == null || newItem == null) return Task.FromResult(default(T)); + if (oldItem == null || newItem == null) return Task.FromResult(default(Champion)); if (!collection.Contains(oldItem)) { - return Task.FromResult(default(T)); + return Task.FromResult(default(Champion)); } collection.Remove(oldItem!); collection.Add(newItem!); - return Task.FromResult(newItem); + return Task.FromResult(newItem); } } } diff --git a/Sources/DBEntitiesWithStub/DBEntitiesWithStub.csproj b/Sources/DBEntitiesWithStub/DBEntitiesWithStub.csproj index 84c39a9..562e5b1 100644 --- a/Sources/DBEntitiesWithStub/DBEntitiesWithStub.csproj +++ b/Sources/DBEntitiesWithStub/DBEntitiesWithStub.csproj @@ -7,6 +7,7 @@ + diff --git a/Sources/EntityFrameworkLib/ChampionEntity.cs b/Sources/EntityFrameworkLib/ChampionEntity.cs index 5e8edda..d05b33e 100644 --- a/Sources/EntityFrameworkLib/ChampionEntity.cs +++ b/Sources/EntityFrameworkLib/ChampionEntity.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Reflection.PortableExecutable; using System.Text; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.Design; @@ -11,11 +13,20 @@ namespace EntityFrameworkLib { public class ChampionEntity { - public int Id { get; set; } + [Key] + [MaxLength(256)] public string Name { get; set; } + [MaxLength(500)] public string Bio { get; set; } public string Icon { get; set; } - //public LargeImage Image { get; set; } - //public ChampionClass Class { get; set; } + [Required] + public ChampionClass Class { get; set; } + public ICollection Skills { get; set; } + public ICollection Characteristics { get; set; } + public ICollection RunePages { get; set; } + + public int? ImageId { get; set; } + [ForeignKey("ImageId")] + public LargeImageEntity? Image { get; set; } } } diff --git a/Sources/EntityFrameworkLib/CharacteristicEntity.cs b/Sources/EntityFrameworkLib/CharacteristicEntity.cs new file mode 100644 index 0000000..a58afcf --- /dev/null +++ b/Sources/EntityFrameworkLib/CharacteristicEntity.cs @@ -0,0 +1,23 @@ +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 EntityFrameworkLib +{ + public class CharacteristicEntity + { + [Key] + [MaxLength(256)] + public string Name { get; set; } + [Required] + public int Value { get; set; } + [Required] + public string ChampionForeignKey { get; set; } + [ForeignKey("ChampionForeignKey")] + public ChampionEntity Champion { get; set; } + } +} diff --git a/Sources/EntityFrameworkLib/EntityFrameworkLib.csproj b/Sources/EntityFrameworkLib/EntityFrameworkLib.csproj index 4661632..ed40670 100644 --- a/Sources/EntityFrameworkLib/EntityFrameworkLib.csproj +++ b/Sources/EntityFrameworkLib/EntityFrameworkLib.csproj @@ -9,6 +9,7 @@ + all diff --git a/Sources/EntityFrameworkLib/EnumChampionClass.cs b/Sources/EntityFrameworkLib/EnumChampionClass.cs new file mode 100644 index 0000000..92dc3bc --- /dev/null +++ b/Sources/EntityFrameworkLib/EnumChampionClass.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFrameworkLib +{ + public enum EnumChampionClass + { + Unknown, + Assassin, + Fighter, + Mage, + Marksman, + Support, + Tank + } +} diff --git a/Sources/EntityFrameworkLib/LargeImageEntity.cs b/Sources/EntityFrameworkLib/LargeImageEntity.cs new file mode 100644 index 0000000..e4ad130 --- /dev/null +++ b/Sources/EntityFrameworkLib/LargeImageEntity.cs @@ -0,0 +1,20 @@ +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 EntityFrameworkLib +{ + [Table("t_LargeImage")] + public class LargeImageEntity + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int Id { get; set; } + [Required] + public string Base64 { get; set; } + } +} diff --git a/Sources/EntityFrameworkLib/LolContext.cs b/Sources/EntityFrameworkLib/LolContext.cs index 8f5271c..1d9510f 100644 --- a/Sources/EntityFrameworkLib/LolContext.cs +++ b/Sources/EntityFrameworkLib/LolContext.cs @@ -8,8 +8,15 @@ namespace EntityFrameworkLib public class LolContext : DbContext { public DbSet Champions { get; set; } + public DbSet Characteristics { get; set; } + public DbSet Skins { get; set; } + public DbSet Skills { get; set; } + public DbSet Images { get; set; } + public DbSet Runes { get; set; } + public DbSet RunesPage { get; set; } + public DbSet RunePageRunes { get; set; } public LolContext() { } - public LolContext(DbContextOptions options) + public LolContext(DbContextOptions options) : base(options) { } protected override void OnConfiguring(DbContextOptionsBuilder options) @@ -20,13 +27,17 @@ namespace EntityFrameworkLib } } - /*protected override void OnModelCreating(ModelBuilder modelBuilder) + protected override void OnModelCreating(ModelBuilder modelBuilder) { + base.OnModelCreating(modelBuilder); + + modelBuilder.Entity().Property(l => l.Id).ValueGeneratedOnAdd(); + modelBuilder.Entity().HasKey(c => new { c.Name, c.ChampionForeignKey }); + modelBuilder.Entity().HasKey(c => new { c.RunePageName, c.RuneName }); + modelBuilder.Entity() - .Property(c => c.Image) - .IsRequired(false); - modelBuilder.Entity() - .HasKey(li => li.Base64); - }*/ + .HasMany(c => c.RunePages) + .WithMany(r => r.Champions); + } } } diff --git a/Sources/EntityFrameworkLib/Mappers/ChampionChanger.cs b/Sources/EntityFrameworkLib/Mappers/ChampionChanger.cs index f479a2f..e9a0cf0 100644 --- a/Sources/EntityFrameworkLib/Mappers/ChampionChanger.cs +++ b/Sources/EntityFrameworkLib/Mappers/ChampionChanger.cs @@ -9,21 +9,43 @@ namespace EntityFrameworkLib.Mappers { public static class ChampionChanger { - public static Champion toModel(this ChampionEntity championEntity) + public static ChampionEntity toEntity(this Champion champion, LolContext context) { - return new Champion(championEntity.Name, championEntity.Bio, championEntity.Icon /*championEntity.Image, championEntity.Class*/); + ChampionEntity? championEntity = context.Champions.Find(champion.Name); + if (championEntity == null) + { + championEntity = new() + { + Name = champion.Name, + Bio = champion.Bio, + Icon = champion.Icon, + Class = champion.Class, + Image = new() { Base64 = champion.Image.Base64 } + }; + championEntity.Skills = champion.Skills.Select(s => s.toEntity(championEntity, context)).ToList(); + championEntity.Characteristics = champion.Characteristics.Select(c => c.toEntity(championEntity, context)).ToList(); + } + return championEntity; } - public static ChampionEntity toEntity(this Champion champion) + public static Champion toModel(this ChampionEntity championEntity) { - return new ChampionEntity + var champion = new Champion(championEntity.Name, championEntity.Class, championEntity.Icon, "", championEntity.Bio); + if(championEntity.Skills != null) + { + foreach(var s in championEntity.Skills) + { + champion.AddSkill(s.toModel()); + } + } + if(championEntity.Characteristics != null) { - Name = champion.Name, - Bio = champion.Bio, - Icon = champion.Icon, - //Image = champion.Image, - //Class = champion.Class, - }; + foreach(var c in championEntity.Characteristics) + { + champion.AddCharacteristics(c.toModel()); + } + } + return champion; } } } diff --git a/Sources/EntityFrameworkLib/Mappers/CharacteristicChanger.cs b/Sources/EntityFrameworkLib/Mappers/CharacteristicChanger.cs new file mode 100644 index 0000000..8aa62d7 --- /dev/null +++ b/Sources/EntityFrameworkLib/Mappers/CharacteristicChanger.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection.PortableExecutable; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFrameworkLib.Mappers +{ + public static class CharacteristicChanger + { + public static CharacteristicEntity toEntity(this KeyValuePair item, ChampionEntity championEntity, LolContext context) + { + var characteristicEntity = new CharacteristicEntity(); + if(characteristicEntity == null) + { + return new() + { + Name = item.Key, + Value = item.Value, + ChampionForeignKey = championEntity.Name + }; + } + return characteristicEntity; + } + + public static Tuple toModel(this CharacteristicEntity characteristicEntity) + => new(characteristicEntity.Name, characteristicEntity.Value); + } +} diff --git a/Sources/EntityFrameworkLib/Mappers/LargeImageChanger.cs b/Sources/EntityFrameworkLib/Mappers/LargeImageChanger.cs new file mode 100644 index 0000000..0f8ad9a --- /dev/null +++ b/Sources/EntityFrameworkLib/Mappers/LargeImageChanger.cs @@ -0,0 +1,28 @@ +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFrameworkLib.Mappers +{ + public static class LargeImageChanger + { + public static int Id { get; private set; } + + public static LargeImage toModel(this LargeImageEntity imageEntity) + { + return new LargeImage(imageEntity.Base64) { Id = imageEntity.Id }; + } + + public static LargeImageEntity toEntity(this LargeImage image) + { + return new LargeImageEntity + { + Id = image.Id, + Base64 = image.Base64 + }; + } + } +} diff --git a/Sources/EntityFrameworkLib/Mappers/SkillChanger.cs b/Sources/EntityFrameworkLib/Mappers/SkillChanger.cs new file mode 100644 index 0000000..fa29eb1 --- /dev/null +++ b/Sources/EntityFrameworkLib/Mappers/SkillChanger.cs @@ -0,0 +1,33 @@ +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFrameworkLib.Mappers +{ + public static class SkillChanger + { + public static SkillEntity toEntity(this Skill skill, ChampionEntity championEntity, LolContext context) + { + var skillEntity = context.Skills.Find(skill.Name); + if (skillEntity == null) + { + return new() + { + Name = skill.Name, + Description = skill.Description, + Type = skill.Type, + Champions = new List() { championEntity } + }; + } + skillEntity!.Champions?.Add(championEntity); + return skillEntity; + } + + public static Skill toModel(this SkillEntity skillEntity) + => new(skillEntity.Name, skillEntity.Type, skillEntity.Description); + } +} diff --git a/Sources/EntityFrameworkLib/Mappers/SkinChanger.cs b/Sources/EntityFrameworkLib/Mappers/SkinChanger.cs new file mode 100644 index 0000000..42942f0 --- /dev/null +++ b/Sources/EntityFrameworkLib/Mappers/SkinChanger.cs @@ -0,0 +1,30 @@ +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFrameworkLib.Mappers +{ + public static class SkinChanger + { + public static Skin toModel(this SkinEntity skinEntity) + { + return new Skin(skinEntity.Name, skinEntity.Description, skinEntity.Icon, skinEntity.Price /*championEntity.Image, championEntity.Class*/); + } + + public static SkinEntity toEntity(this Skin skin) + { + return new SkinEntity + { + Name = skin.Name, + Description = skin.Description, + Icon = skin.Icon, + Price = skin.Price + //Image = champion.Image, + //Class = champion.Class, + }; + } + } +} diff --git a/Sources/EntityFrameworkLib/Migrations/20230201082358_myFirstMigration.Designer.cs b/Sources/EntityFrameworkLib/Migrations/20230201082358_myFirstMigration.Designer.cs deleted file mode 100644 index ec3f117..0000000 --- a/Sources/EntityFrameworkLib/Migrations/20230201082358_myFirstMigration.Designer.cs +++ /dev/null @@ -1,47 +0,0 @@ -// -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("20230201082358_myFirstMigration")] - partial class myFirstMigration - { - /// - 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/20230201082358_myFirstMigration.cs b/Sources/EntityFrameworkLib/Migrations/20230201082358_myFirstMigration.cs deleted file mode 100644 index 41948c8..0000000 --- a/Sources/EntityFrameworkLib/Migrations/20230201082358_myFirstMigration.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace EntityFrameworkLib.Migrations -{ - /// - public partial class myFirstMigration : 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/EntityFrameworkLib/Migrations/20230201084126_projet_SQLite.Designer.cs b/Sources/EntityFrameworkLib/Migrations/20230201084126_projet_SQLite.Designer.cs deleted file mode 100644 index 267bc82..0000000 --- a/Sources/EntityFrameworkLib/Migrations/20230201084126_projet_SQLite.Designer.cs +++ /dev/null @@ -1,47 +0,0 @@ -// -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("20230201084126_projet_SQLite")] - partial class projetSQLite - { - /// - 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/20230201084126_projet_SQLite.cs b/Sources/EntityFrameworkLib/Migrations/20230201084126_projet_SQLite.cs deleted file mode 100644 index f946f4c..0000000 --- a/Sources/EntityFrameworkLib/Migrations/20230201084126_projet_SQLite.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace EntityFrameworkLib.Migrations -{ - /// - public partial class projetSQLite : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - - } - } -} diff --git a/Sources/EntityFrameworkLib/Migrations/20230201103421_migration_projet.Designer.cs b/Sources/EntityFrameworkLib/Migrations/20230201103421_migration_projet.Designer.cs deleted file mode 100644 index aa7615e..0000000 --- a/Sources/EntityFrameworkLib/Migrations/20230201103421_migration_projet.Designer.cs +++ /dev/null @@ -1,47 +0,0 @@ -// -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 deleted file mode 100644 index 6f871ae..0000000 --- a/Sources/EntityFrameworkLib/Migrations/20230201103421_migration_projet.cs +++ /dev/null @@ -1,22 +0,0 @@ -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/20230325144614_AllMigrations.Designer.cs b/Sources/EntityFrameworkLib/Migrations/20230325144614_AllMigrations.Designer.cs new file mode 100644 index 0000000..7e43e52 --- /dev/null +++ b/Sources/EntityFrameworkLib/Migrations/20230325144614_AllMigrations.Designer.cs @@ -0,0 +1,333 @@ +// +using System; +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("20230325144614_AllMigrations")] + partial class AllMigrations + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("ChampionEntityRunePageEntity", b => + { + b.Property("ChampionsName") + .HasColumnType("TEXT"); + + b.Property("RunePagesName") + .HasColumnType("TEXT"); + + b.HasKey("ChampionsName", "RunePagesName"); + + b.HasIndex("RunePagesName"); + + b.ToTable("ChampionEntityRunePageEntity"); + }); + + modelBuilder.Entity("ChampionEntitySkillEntity", b => + { + b.Property("ChampionsName") + .HasColumnType("TEXT"); + + b.Property("SkillsName") + .HasColumnType("TEXT"); + + b.HasKey("ChampionsName", "SkillsName"); + + b.HasIndex("SkillsName"); + + b.ToTable("ChampionEntitySkillEntity"); + }); + + modelBuilder.Entity("EntityFrameworkLib.ChampionEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("Bio") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Class") + .HasColumnType("INTEGER"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ImageId") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.HasIndex("ImageId"); + + b.ToTable("Champions"); + }); + + modelBuilder.Entity("EntityFrameworkLib.CharacteristicEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("ChampionForeignKey") + .HasColumnType("TEXT"); + + b.Property("Value") + .HasColumnType("INTEGER"); + + b.HasKey("Name", "ChampionForeignKey"); + + b.HasIndex("ChampionForeignKey"); + + b.ToTable("Characteristics"); + }); + + modelBuilder.Entity("EntityFrameworkLib.LargeImageEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Base64") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("t_LargeImage"); + }); + + modelBuilder.Entity("EntityFrameworkLib.RuneEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("ImageId") + .HasColumnType("INTEGER"); + + b.Property("RuneFamily") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.HasIndex("ImageId"); + + b.ToTable("Runes"); + }); + + modelBuilder.Entity("EntityFrameworkLib.RunePageEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("RunesPage"); + }); + + modelBuilder.Entity("EntityFrameworkLib.RunePageRuneEntity", b => + { + b.Property("RunePageName") + .HasColumnType("TEXT"); + + b.Property("RuneName") + .HasColumnType("TEXT"); + + b.Property("Category") + .HasColumnType("INTEGER"); + + b.HasKey("RunePageName", "RuneName"); + + b.HasIndex("RuneName"); + + b.ToTable("RunePageRunes"); + }); + + modelBuilder.Entity("EntityFrameworkLib.SkillEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.ToTable("Skills"); + }); + + modelBuilder.Entity("EntityFrameworkLib.SkinEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("ChampionForeignKey") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ImageId") + .HasColumnType("INTEGER"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Name"); + + b.HasIndex("ChampionForeignKey"); + + b.HasIndex("ImageId"); + + b.ToTable("Skins"); + }); + + modelBuilder.Entity("ChampionEntityRunePageEntity", b => + { + b.HasOne("EntityFrameworkLib.ChampionEntity", null) + .WithMany() + .HasForeignKey("ChampionsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameworkLib.RunePageEntity", null) + .WithMany() + .HasForeignKey("RunePagesName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ChampionEntitySkillEntity", b => + { + b.HasOne("EntityFrameworkLib.ChampionEntity", null) + .WithMany() + .HasForeignKey("ChampionsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameworkLib.SkillEntity", null) + .WithMany() + .HasForeignKey("SkillsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("EntityFrameworkLib.ChampionEntity", b => + { + b.HasOne("EntityFrameworkLib.LargeImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageId"); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("EntityFrameworkLib.CharacteristicEntity", b => + { + b.HasOne("EntityFrameworkLib.ChampionEntity", "Champion") + .WithMany("Characteristics") + .HasForeignKey("ChampionForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Champion"); + }); + + modelBuilder.Entity("EntityFrameworkLib.RuneEntity", b => + { + b.HasOne("EntityFrameworkLib.LargeImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageId"); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("EntityFrameworkLib.RunePageRuneEntity", b => + { + b.HasOne("EntityFrameworkLib.RuneEntity", "Rune") + .WithMany("RunePages") + .HasForeignKey("RuneName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameworkLib.RunePageEntity", "RunePage") + .WithMany("Runes") + .HasForeignKey("RunePageName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Rune"); + + b.Navigation("RunePage"); + }); + + modelBuilder.Entity("EntityFrameworkLib.SkinEntity", b => + { + b.HasOne("EntityFrameworkLib.ChampionEntity", "Champion") + .WithMany() + .HasForeignKey("ChampionForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameworkLib.LargeImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageId"); + + b.Navigation("Champion"); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("EntityFrameworkLib.ChampionEntity", b => + { + b.Navigation("Characteristics"); + }); + + modelBuilder.Entity("EntityFrameworkLib.RuneEntity", b => + { + b.Navigation("RunePages"); + }); + + modelBuilder.Entity("EntityFrameworkLib.RunePageEntity", b => + { + b.Navigation("Runes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EntityFrameworkLib/Migrations/20230325144614_AllMigrations.cs b/Sources/EntityFrameworkLib/Migrations/20230325144614_AllMigrations.cs new file mode 100644 index 0000000..ef000a9 --- /dev/null +++ b/Sources/EntityFrameworkLib/Migrations/20230325144614_AllMigrations.cs @@ -0,0 +1,283 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EntityFrameworkLib.Migrations +{ + /// + public partial class AllMigrations : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "RunesPage", + columns: table => new + { + Name = table.Column(type: "TEXT", maxLength: 256, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RunesPage", x => x.Name); + }); + + migrationBuilder.CreateTable( + name: "Skills", + columns: table => new + { + Name = table.Column(type: "TEXT", maxLength: 256, nullable: false), + Description = table.Column(type: "TEXT", maxLength: 500, nullable: false), + Type = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Skills", x => x.Name); + }); + + migrationBuilder.CreateTable( + name: "t_LargeImage", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Base64 = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_t_LargeImage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Champions", + columns: table => new + { + Name = table.Column(type: "TEXT", maxLength: 256, nullable: false), + Bio = table.Column(type: "TEXT", maxLength: 500, nullable: false), + Icon = table.Column(type: "TEXT", nullable: false), + Class = table.Column(type: "INTEGER", nullable: false), + ImageId = table.Column(type: "INTEGER", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Champions", x => x.Name); + table.ForeignKey( + name: "FK_Champions_t_LargeImage_ImageId", + column: x => x.ImageId, + principalTable: "t_LargeImage", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Runes", + columns: table => new + { + Name = table.Column(type: "TEXT", maxLength: 256, nullable: false), + Description = table.Column(type: "TEXT", maxLength: 500, nullable: false), + RuneFamily = table.Column(type: "INTEGER", nullable: false), + ImageId = table.Column(type: "INTEGER", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Runes", x => x.Name); + table.ForeignKey( + name: "FK_Runes_t_LargeImage_ImageId", + column: x => x.ImageId, + principalTable: "t_LargeImage", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "ChampionEntityRunePageEntity", + columns: table => new + { + ChampionsName = table.Column(type: "TEXT", nullable: false), + RunePagesName = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ChampionEntityRunePageEntity", x => new { x.ChampionsName, x.RunePagesName }); + table.ForeignKey( + name: "FK_ChampionEntityRunePageEntity_Champions_ChampionsName", + column: x => x.ChampionsName, + principalTable: "Champions", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ChampionEntityRunePageEntity_RunesPage_RunePagesName", + column: x => x.RunePagesName, + principalTable: "RunesPage", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ChampionEntitySkillEntity", + columns: table => new + { + ChampionsName = table.Column(type: "TEXT", nullable: false), + SkillsName = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ChampionEntitySkillEntity", x => new { x.ChampionsName, x.SkillsName }); + table.ForeignKey( + name: "FK_ChampionEntitySkillEntity_Champions_ChampionsName", + column: x => x.ChampionsName, + principalTable: "Champions", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ChampionEntitySkillEntity_Skills_SkillsName", + column: x => x.SkillsName, + principalTable: "Skills", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Characteristics", + columns: table => new + { + Name = table.Column(type: "TEXT", maxLength: 256, nullable: false), + ChampionForeignKey = table.Column(type: "TEXT", nullable: false), + Value = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Characteristics", x => new { x.Name, x.ChampionForeignKey }); + table.ForeignKey( + name: "FK_Characteristics_Champions_ChampionForeignKey", + column: x => x.ChampionForeignKey, + principalTable: "Champions", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Skins", + columns: table => new + { + Name = table.Column(type: "TEXT", maxLength: 256, nullable: false), + Description = table.Column(type: "TEXT", maxLength: 500, nullable: false), + Icon = table.Column(type: "TEXT", nullable: false), + Price = table.Column(type: "REAL", nullable: false), + ChampionForeignKey = table.Column(type: "TEXT", nullable: false), + ImageId = table.Column(type: "INTEGER", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Skins", x => x.Name); + table.ForeignKey( + name: "FK_Skins_Champions_ChampionForeignKey", + column: x => x.ChampionForeignKey, + principalTable: "Champions", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Skins_t_LargeImage_ImageId", + column: x => x.ImageId, + principalTable: "t_LargeImage", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "RunePageRunes", + columns: table => new + { + RuneName = table.Column(type: "TEXT", nullable: false), + RunePageName = table.Column(type: "TEXT", nullable: false), + Category = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RunePageRunes", x => new { x.RunePageName, x.RuneName }); + table.ForeignKey( + name: "FK_RunePageRunes_RunesPage_RunePageName", + column: x => x.RunePageName, + principalTable: "RunesPage", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_RunePageRunes_Runes_RuneName", + column: x => x.RuneName, + principalTable: "Runes", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ChampionEntityRunePageEntity_RunePagesName", + table: "ChampionEntityRunePageEntity", + column: "RunePagesName"); + + migrationBuilder.CreateIndex( + name: "IX_ChampionEntitySkillEntity_SkillsName", + table: "ChampionEntitySkillEntity", + column: "SkillsName"); + + migrationBuilder.CreateIndex( + name: "IX_Champions_ImageId", + table: "Champions", + column: "ImageId"); + + migrationBuilder.CreateIndex( + name: "IX_Characteristics_ChampionForeignKey", + table: "Characteristics", + column: "ChampionForeignKey"); + + migrationBuilder.CreateIndex( + name: "IX_RunePageRunes_RuneName", + table: "RunePageRunes", + column: "RuneName"); + + migrationBuilder.CreateIndex( + name: "IX_Runes_ImageId", + table: "Runes", + column: "ImageId"); + + migrationBuilder.CreateIndex( + name: "IX_Skins_ChampionForeignKey", + table: "Skins", + column: "ChampionForeignKey"); + + migrationBuilder.CreateIndex( + name: "IX_Skins_ImageId", + table: "Skins", + column: "ImageId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ChampionEntityRunePageEntity"); + + migrationBuilder.DropTable( + name: "ChampionEntitySkillEntity"); + + migrationBuilder.DropTable( + name: "Characteristics"); + + migrationBuilder.DropTable( + name: "RunePageRunes"); + + migrationBuilder.DropTable( + name: "Skins"); + + migrationBuilder.DropTable( + name: "Skills"); + + migrationBuilder.DropTable( + name: "RunesPage"); + + migrationBuilder.DropTable( + name: "Runes"); + + migrationBuilder.DropTable( + name: "Champions"); + + migrationBuilder.DropTable( + name: "t_LargeImage"); + } + } +} diff --git a/Sources/EntityFrameworkLib/Migrations/ChampionContextModelSnapshot.cs b/Sources/EntityFrameworkLib/Migrations/ChampionContextModelSnapshot.cs deleted file mode 100644 index f6b76d8..0000000 --- a/Sources/EntityFrameworkLib/Migrations/ChampionContextModelSnapshot.cs +++ /dev/null @@ -1,44 +0,0 @@ -// -using EntityFrameworkLib; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EntityFrameworkLib.Migrations -{ - [DbContext(typeof(LolContext))] - partial class ChampionContextModelSnapshot : 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/EntityFrameworkLib/Migrations/LolContextModelSnapshot.cs b/Sources/EntityFrameworkLib/Migrations/LolContextModelSnapshot.cs new file mode 100644 index 0000000..1004e89 --- /dev/null +++ b/Sources/EntityFrameworkLib/Migrations/LolContextModelSnapshot.cs @@ -0,0 +1,330 @@ +// +using System; +using EntityFrameworkLib; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EntityFrameworkLib.Migrations +{ + [DbContext(typeof(LolContext))] + partial class LolContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("ChampionEntityRunePageEntity", b => + { + b.Property("ChampionsName") + .HasColumnType("TEXT"); + + b.Property("RunePagesName") + .HasColumnType("TEXT"); + + b.HasKey("ChampionsName", "RunePagesName"); + + b.HasIndex("RunePagesName"); + + b.ToTable("ChampionEntityRunePageEntity"); + }); + + modelBuilder.Entity("ChampionEntitySkillEntity", b => + { + b.Property("ChampionsName") + .HasColumnType("TEXT"); + + b.Property("SkillsName") + .HasColumnType("TEXT"); + + b.HasKey("ChampionsName", "SkillsName"); + + b.HasIndex("SkillsName"); + + b.ToTable("ChampionEntitySkillEntity"); + }); + + modelBuilder.Entity("EntityFrameworkLib.ChampionEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("Bio") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Class") + .HasColumnType("INTEGER"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ImageId") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.HasIndex("ImageId"); + + b.ToTable("Champions"); + }); + + modelBuilder.Entity("EntityFrameworkLib.CharacteristicEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("ChampionForeignKey") + .HasColumnType("TEXT"); + + b.Property("Value") + .HasColumnType("INTEGER"); + + b.HasKey("Name", "ChampionForeignKey"); + + b.HasIndex("ChampionForeignKey"); + + b.ToTable("Characteristics"); + }); + + modelBuilder.Entity("EntityFrameworkLib.LargeImageEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Base64") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("t_LargeImage"); + }); + + modelBuilder.Entity("EntityFrameworkLib.RuneEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("ImageId") + .HasColumnType("INTEGER"); + + b.Property("RuneFamily") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.HasIndex("ImageId"); + + b.ToTable("Runes"); + }); + + modelBuilder.Entity("EntityFrameworkLib.RunePageEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("RunesPage"); + }); + + modelBuilder.Entity("EntityFrameworkLib.RunePageRuneEntity", b => + { + b.Property("RunePageName") + .HasColumnType("TEXT"); + + b.Property("RuneName") + .HasColumnType("TEXT"); + + b.Property("Category") + .HasColumnType("INTEGER"); + + b.HasKey("RunePageName", "RuneName"); + + b.HasIndex("RuneName"); + + b.ToTable("RunePageRunes"); + }); + + modelBuilder.Entity("EntityFrameworkLib.SkillEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.ToTable("Skills"); + }); + + modelBuilder.Entity("EntityFrameworkLib.SkinEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("ChampionForeignKey") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ImageId") + .HasColumnType("INTEGER"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Name"); + + b.HasIndex("ChampionForeignKey"); + + b.HasIndex("ImageId"); + + b.ToTable("Skins"); + }); + + modelBuilder.Entity("ChampionEntityRunePageEntity", b => + { + b.HasOne("EntityFrameworkLib.ChampionEntity", null) + .WithMany() + .HasForeignKey("ChampionsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameworkLib.RunePageEntity", null) + .WithMany() + .HasForeignKey("RunePagesName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ChampionEntitySkillEntity", b => + { + b.HasOne("EntityFrameworkLib.ChampionEntity", null) + .WithMany() + .HasForeignKey("ChampionsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameworkLib.SkillEntity", null) + .WithMany() + .HasForeignKey("SkillsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("EntityFrameworkLib.ChampionEntity", b => + { + b.HasOne("EntityFrameworkLib.LargeImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageId"); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("EntityFrameworkLib.CharacteristicEntity", b => + { + b.HasOne("EntityFrameworkLib.ChampionEntity", "Champion") + .WithMany("Characteristics") + .HasForeignKey("ChampionForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Champion"); + }); + + modelBuilder.Entity("EntityFrameworkLib.RuneEntity", b => + { + b.HasOne("EntityFrameworkLib.LargeImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageId"); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("EntityFrameworkLib.RunePageRuneEntity", b => + { + b.HasOne("EntityFrameworkLib.RuneEntity", "Rune") + .WithMany("RunePages") + .HasForeignKey("RuneName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameworkLib.RunePageEntity", "RunePage") + .WithMany("Runes") + .HasForeignKey("RunePageName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Rune"); + + b.Navigation("RunePage"); + }); + + modelBuilder.Entity("EntityFrameworkLib.SkinEntity", b => + { + b.HasOne("EntityFrameworkLib.ChampionEntity", "Champion") + .WithMany() + .HasForeignKey("ChampionForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameworkLib.LargeImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageId"); + + b.Navigation("Champion"); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("EntityFrameworkLib.ChampionEntity", b => + { + b.Navigation("Characteristics"); + }); + + modelBuilder.Entity("EntityFrameworkLib.RuneEntity", b => + { + b.Navigation("RunePages"); + }); + + modelBuilder.Entity("EntityFrameworkLib.RunePageEntity", b => + { + b.Navigation("Runes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EntityFrameworkLib/RuneEntity.cs b/Sources/EntityFrameworkLib/RuneEntity.cs new file mode 100644 index 0000000..aa31b65 --- /dev/null +++ b/Sources/EntityFrameworkLib/RuneEntity.cs @@ -0,0 +1,28 @@ +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 EntityFrameworkLib +{ + public class RuneEntity + { + [Key] + [MaxLength(256)] + public string Name { get; set; } + [Required] + [MaxLength(500)] + public string Description { get; set; } + [Required] + public RuneFamily RuneFamily { get; set; } + public ICollection? RunePages { get; set; } + + public int? ImageId { get; set; } + [ForeignKey("ImageId")] + public LargeImageEntity? Image { get; set; } + } +} diff --git a/Sources/EntityFrameworkLib/RunePageEntity.cs b/Sources/EntityFrameworkLib/RunePageEntity.cs new file mode 100644 index 0000000..ea20621 --- /dev/null +++ b/Sources/EntityFrameworkLib/RunePageEntity.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFrameworkLib +{ + public class RunePageEntity + { + [Key] + [MaxLength(256)] + public string Name { get; set; } + + public ICollection Runes { get; set; } + public ICollection Champions { get; set; } + } +} diff --git a/Sources/EntityFrameworkLib/RunePageRuneEntity.cs b/Sources/EntityFrameworkLib/RunePageRuneEntity.cs new file mode 100644 index 0000000..d41657c --- /dev/null +++ b/Sources/EntityFrameworkLib/RunePageRuneEntity.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static Model.RunePage; + +namespace EntityFrameworkLib +{ + public class RunePageRuneEntity + { + public Category Category { get; set; } + + [ForeignKey("RuneName")] + public RuneEntity Rune { get; set; } + public string RuneName { get; set; } + + [ForeignKey("RunePageName")] + public RunePageEntity RunePage { get; set; } + public string RunePageName { get; set; } + } +} diff --git a/Sources/EntityFrameworkLib/SkillEntity.cs b/Sources/EntityFrameworkLib/SkillEntity.cs new file mode 100644 index 0000000..36d0dcb --- /dev/null +++ b/Sources/EntityFrameworkLib/SkillEntity.cs @@ -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 EntityFrameworkLib +{ + public class SkillEntity + { + [Key] + [MaxLength(256)] + public string Name { get; set; } + [Required] + [MaxLength(500)] + public string Description { get; set; } + [Required] + public SkillType Type { get; set; } + public ICollection? Champions { get; set; } + } +} diff --git a/Sources/EntityFrameworkLib/Skin.cs b/Sources/EntityFrameworkLib/Skin.cs deleted file mode 100644 index f2f5c8a..0000000 --- a/Sources/EntityFrameworkLib/Skin.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EntityFrameworkLib -{ - public class Skin - { - public string Name { get; set; } - public string Description { get; set; } - public string Icon { get; set; } - public float Price { get; set; } - } -} diff --git a/Sources/EntityFrameworkLib/SkinEntity.cs b/Sources/EntityFrameworkLib/SkinEntity.cs new file mode 100644 index 0000000..4131529 --- /dev/null +++ b/Sources/EntityFrameworkLib/SkinEntity.cs @@ -0,0 +1,33 @@ +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 EntityFrameworkLib +{ + public class SkinEntity + { + [Key] + [MaxLength(256)] + public string Name { get; set; } + [Required] + [MaxLength(500)] + public string Description { get; set; } + [Required] + public string Icon { get; set; } + [Required] + public float Price { get; set; } + + [Required] + public string ChampionForeignKey { get; set; } + [ForeignKey("ChampionForeignKey")] + public ChampionEntity Champion { get; set; } + + public int? ImageId { get; set; } + [ForeignKey("ImageId")] + public LargeImageEntity? Image { get; set; } + } +} diff --git a/Sources/EntityFrameworkLib/projet.Champions.db b/Sources/EntityFrameworkLib/projet.Champions.db new file mode 100644 index 0000000000000000000000000000000000000000..5ff60a7985984bb219fc3d96fac5746f77449fd3 GIT binary patch literal 135168 zcmeI3OK%(36@WREL`t+M`4MNLyfh|i*o54~a-1kZU??;_atKS5Owlg{0l~;qg)l|g z914g~Z>ZRH5Ok4W&@8j+FUc<5b=93WT?S}@YtTVzp7Hf0_C|Tgd)A`R(L~nI9&{CO*kLOno>0bTpH?lzeyO$K+@-C?jrM%3mUZ z{3|K-lBy&ct-Hoo=7Xkih+2K8vu)qk*6%f1W^La7I{Ed?v9vljr#xR&XC;+OSy zeWPQv8)m1mVTNvx7b|+9s%zE4hm3 zmFTl|zp>p~+HM<-&DJ$zH>TmudUHn%QYu&Vt9m6oPI0xoUab^Ft(IH6R_oJbtx{Sk zRPJck^gG&FN1t=H!eQZgSFzxLOML@c0_>iqe-)g-(rQI7T`jxPytaWBd99)^=@q?P z)Yp4zn1Yz2TV7i&YghDTUBE3C){BKJdNz~4bUdYApNlhNXwJ3yP{D~u=cm)^;-d0o z+cT{_1-;d2basXHn@#7^)3>kUXrH;G2k05z8_FEu0k-4;4T6?%OdBUvHnJ>RSUVsn z-pbKq`&RDR+toPQ)K29KSUJ}FV)Sz6WIe*oW~4@e8d)8uVjqvYel(>Tivv6^MlH+t zqN|QQs%F!wt}EZnMR;Llr)8|wH;pJql?O_)An&nues|n z&tiYCizDGT<(eVYtXtEvXU(gK^ijD|c2j?deLVHnR7$<4Kbxm|@?3x+XO(NG_dYt3 zR#jDbblvt>TOa$^r0juqSbZb%t^zT}<(duxRo)zwm2$XU_LRqvs@ zTsMsmE`}UHIC1yTjv>VQ*MRuS-BXPoMo4f$Hx4h=^FI zJeNwTi!*WNc4XQCzX%%A4@c|=uY0w(zFAAQ{a9KTqw*yE@}4oCb*-~TlQu-5>ip;+ z&-8`WoMplqVXS*wNvjJB%HFE2ajm8=tu!{{cF3RQA(!N&llnh7b&MUA6Y!&q>ry=v*JRT{%1n` z;{yQ*KmY;|fB*y_009U<00Izz!0(R0ACwVYy>R}*d*|P~@c#V8iyzEitQDF~|J=e{ zc<1~(7cydA%Jjby;vXLfKmY;|fB*y_009U<00Izz00e%g1ZGF{i9v?|*86|)pZ@tk z00Izz00bZa0SG_<0uX=z1RyZP1g!V}@}`5P$##AOHafKmY;|fB*y_K>m*pKmY;| zfB*y_009U<00Izz00f4g0Du2K{5EEW5P$##AOHafKmY;|fB*y_00G|r;{yW&qbn0I;jpCQ}c73B`v>Rrpv0;X8j~6R?p{i@u!sTUM z%Y|xl+SzPI6Q5kUzGdXJs(!nwl~={jjpgNYZk6b>b-%IQTH0hPZ&3bc3 z3{omr^{aX%JWg@7yk4yoM6H%vyH@MdWUW$KDOB!g*YrEuSx299w!&fIc~`OEfJ=P? zS_15zrhgTjz|v|(FI_FW(!92T7J03rFXzypm-}skL_EzXKz>IXj40tFJR?Z?~BpP znUnPhH=B_f1!`nD8sv*|)8}(XukVX`q}Sh>LQdPqDZS>d$2^Puy)KS~-;`^HRI_eP%bqo_BGO0Y zO4&{QA@=dq>Hj9~+|!@UQ$2Yuz>u@bwbOea9Z9RIsyw=G`>U;w{cBS8K)bBxY7q;b z7Fx;N9svjOHpMH3xzTRi?}&XdW;e9@F4eahO|f0ZY>BzjmLOlc8)(qmcY~^k?afxD z)~PMm+oFrrujcobS2(X&woW5 z;;;?Sy2SQ03W{2>#BAp84*@bXq-qTG?|}{-DnUug9g) za>1&ettGd1L(1^;CHD;2TPxhCu9nI|&Wc{HdJo;@x@mlHG2{TkiM!{=((25NviGr# z!r3>S-ziyDe@l%Id&4?{#9`s}|5RCn)3M8rbnxl~GBoQX5HBhwD}MbMCbIAT9| z-K)Lz&04bU$I`kOl_%+!_l)tZYn?Tkv>^&r=SK&5rZ24KEECoUW8K?IT3uLB_Ev3; zYc+jorLozrTg#>SsYq0|+q;p4NqHubZF;lv$FzJ+%3Z=nj2S4xrfco(yE_}5n?~F0 zU)u$ZQZl7}z7S`)NIA9n$l?)^#g1EIF|fdV)}<{CwuD1<0DHGpG=%g{bT&6 zRA%hv=)Xrl9rMlyKNDZyu5t(I9{8O?giCBIdz!!8obksrt9|NKT;T|A?7-}2^UHSyPKJBYKEVyX1)NKyTrdNTbwOSUzZ zy}akUr(RF1x8{`YiYHynJ$N?cCn7zzp%!oT=@M!XF@&R6sGX&mD6#{?p0r&4%bB$L z{;blS2&m{pj~;%nm-%LtE^=F6v{NjZqC5XuTK#NM>D~y7a*_&rk9G44``S)?Jn4OH z-iXzvuc?&lTfQGVsHJdEb}rvtQq$_Du5`Deb@u$mRolCb(A=wXTE4!I@^b5ND%d{- zxxMFwmRq_>^4AYfrqwfNlqU;*$l^P#*V+0uUvo8c&nKliF|He?S;Y|{j2DM_y#_QX z);q?gh&p1^fMB{M&ak{8t#7ex1p)>4k+Y^_%M-^|zIri-R?=WjCTDf`g*bZ4S)A9$ zu9H(aTPJG(3%pz3cNpoi2~Nw+B7H+Rn%KYNG>DTvNU{i$K6*8!uAGSrlDw(e^KimO zU#A(dyV*fe{*^(Asl6q52jY)LPT2YX6T=JtTc+LM71_D$vYt~pa~>Erx;+Bc_grrO z(0@Qey4G%N2;+&9`Q`8_xxZEf7EL*{^)&GI(OzB~dv@T^@>ZeV0clW%?0sI_KnvLi zy#@mh#G`%C(I%Msc}sszleO@sD2opEwEWOL$@o8y-oKtXmgcRBCM8b4mA5Lt#u@kd zX%VUMrbWEeAYH_!c55o7{wn9!{Qds{r?iNJ00bZa0SG_<0uX=z1Rwwb2pj?d{{H_Epd%6j z5P$##AOHafKmY;|fB*y_aKHq}{|^{A;vfJ42tWV=5P$##AOHafKmY=VK!E)J5TGLx z0uX=z1Rwwb2tWV=5P$##AaKA0$o~%*IN~4x0SG_<0uX=z1Rwwb2tWV=hd_Y*{}7-f z5&{r_00bZa0SG_<0uX=z1R!w01jzpn7&zh}009U<00Izz00bZa0SG_<0*63={QnT3 zBN74-fB*y_009U<00Izz00ba#zy!$u4;VP&AOHafKmY;|fB*y_009U<00M_Vfc*au cpd%6j5P$##AOHafKmY;|fB*y_aKHrq2l#L$m;e9( literal 0 HcmV?d00001 diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index fa67e38..e76f634 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -31,7 +31,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DBWithStub", "DBWithStub", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DBEntitiesWithStub", "DBEntitiesWithStub\DBEntitiesWithStub.csproj", "{C9D40527-6F42-4FA9-8063-554D2A0E9161}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DBDataManager", "DBDataManager\DBDataManager.csproj", "{9596049A-FCBB-4F61-9E48-D3086EAEFF85}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DBDataManager", "DBDataManager\DBDataManager.csproj", "{9596049A-FCBB-4F61-9E48-D3086EAEFF85}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleConfig", "ConsoleConfig\ConsoleConfig.csproj", "{4E2A53C1-E504-42F4-AD36-8384F74577BE}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LolApp", "..\..\..\..\Downloads\EntityFramework_LoL-master\entityframework_lol\Sources\LolApp\LolApp.csproj", "{0C898A04-092A-49AA-BE65-8AE818A2AF50}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ViewModels", "..\..\..\..\Downloads\EntityFramework_LoL-master\entityframework_lol\Sources\ViewModels\ViewModels.csproj", "{3F2F7988-38E0-413A-B1BA-826E6DB3224D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -83,6 +89,20 @@ Global {9596049A-FCBB-4F61-9E48-D3086EAEFF85}.Debug|Any CPU.Build.0 = Debug|Any CPU {9596049A-FCBB-4F61-9E48-D3086EAEFF85}.Release|Any CPU.ActiveCfg = Release|Any CPU {9596049A-FCBB-4F61-9E48-D3086EAEFF85}.Release|Any CPU.Build.0 = Release|Any CPU + {4E2A53C1-E504-42F4-AD36-8384F74577BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4E2A53C1-E504-42F4-AD36-8384F74577BE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4E2A53C1-E504-42F4-AD36-8384F74577BE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4E2A53C1-E504-42F4-AD36-8384F74577BE}.Release|Any CPU.Build.0 = Release|Any CPU + {0C898A04-092A-49AA-BE65-8AE818A2AF50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0C898A04-092A-49AA-BE65-8AE818A2AF50}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0C898A04-092A-49AA-BE65-8AE818A2AF50}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {0C898A04-092A-49AA-BE65-8AE818A2AF50}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0C898A04-092A-49AA-BE65-8AE818A2AF50}.Release|Any CPU.Build.0 = Release|Any CPU + {0C898A04-092A-49AA-BE65-8AE818A2AF50}.Release|Any CPU.Deploy.0 = Release|Any CPU + {3F2F7988-38E0-413A-B1BA-826E6DB3224D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3F2F7988-38E0-413A-B1BA-826E6DB3224D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3F2F7988-38E0-413A-B1BA-826E6DB3224D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3F2F7988-38E0-413A-B1BA-826E6DB3224D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -95,6 +115,7 @@ Global {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} + {4E2A53C1-E504-42F4-AD36-8384F74577BE} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9} diff --git a/Sources/Model/LargeImage.cs b/Sources/Model/LargeImage.cs index 56d6696..48a4386 100644 --- a/Sources/Model/LargeImage.cs +++ b/Sources/Model/LargeImage.cs @@ -3,10 +3,12 @@ namespace Model { public class LargeImage : IEquatable { + public int Id { get; set; } public string Base64 { get; set; } public LargeImage(string base64) { + Id = 0; Base64 = base64; } @@ -23,6 +25,11 @@ namespace Model public override int GetHashCode() => Base64.Substring(0, 10).GetHashCode(); + + public static implicit operator LargeImage(string v) + { + return new LargeImage(v); + } } } diff --git a/Sources/Model/Model.csproj b/Sources/Model/Model.csproj index 7d8ec7e..c1fc9b2 100644 --- a/Sources/Model/Model.csproj +++ b/Sources/Model/Model.csproj @@ -13,6 +13,7 @@ + all diff --git a/Sources/Model/RunePage.cs b/Sources/Model/RunePage.cs index cf56628..e457cfe 100644 --- a/Sources/Model/RunePage.cs +++ b/Sources/Model/RunePage.cs @@ -3,93 +3,94 @@ using System.Collections.ObjectModel; namespace Model { - public partial class RunePage - { - public string Name - { - get => name; - private init - { - if(string.IsNullOrWhiteSpace(value)) - { - throw new ArgumentException("a Rune Page must have a name"); - } - name = value; - } - } - private readonly string name = null!; + public partial class RunePage + { + public string Name + { + get => name; + private init + { + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("a Rune Page must have a name"); + } + name = value; + } + } + private readonly string name = null!; - public ReadOnlyDictionary Runes { get; private set; } - private Dictionary runes = new Dictionary(); + public ReadOnlyDictionary Runes { get; private set; } + private Dictionary runes = new Dictionary(); - public RunePage(string name) - { - Name = name; - Runes = new ReadOnlyDictionary(runes); - } + public RunePage(string name) + { + Name = name; + Runes = new ReadOnlyDictionary(runes); + } - public Rune? this[Category category] - { - get - { - if(runes.TryGetValue(category, out Rune? rune)) - { - return rune; - } - return null; - } - set - { - if(value == null) - { - runes.Remove(category); - } - runes[category] = value!; - CheckRunes(category); - } - } + public Rune? this[Category category] + { + get + { + if (runes.TryGetValue(category, out Rune? rune)) + { + return rune; + } + return null; + } + set + { + if (value == null) + { + runes.Remove(category); + return; + } + runes[category] = value!; + CheckRunes(category); + } + } - private void CheckRunes(Category newRuneCategory) - { - switch(newRuneCategory) - { - case Category.Major: - UpdateMajorFamily(Category.Minor1, true); - UpdateMajorFamily(Category.Minor2, true); - UpdateMajorFamily(Category.Minor3, true); - UpdateMajorFamily(Category.OtherMinor1, false); - UpdateMajorFamily(Category.OtherMinor2, false); - break; - case Category.Minor1: - case Category.Minor2: - case Category.Minor3: - UpdateMajorFamily(newRuneCategory, true); - break; - case Category.OtherMinor1: - case Category.OtherMinor2: - UpdateMajorFamily(newRuneCategory, false); - break; - } - } + private void CheckRunes(Category newRuneCategory) + { + switch (newRuneCategory) + { + case Category.Major: + UpdateMajorFamily(Category.Minor1, true); + UpdateMajorFamily(Category.Minor2, true); + UpdateMajorFamily(Category.Minor3, true); + UpdateMajorFamily(Category.OtherMinor1, false); + UpdateMajorFamily(Category.OtherMinor2, false); + break; + case Category.Minor1: + case Category.Minor2: + case Category.Minor3: + UpdateMajorFamily(newRuneCategory, true); + break; + case Category.OtherMinor1: + case Category.OtherMinor2: + UpdateMajorFamily(newRuneCategory, false); + break; + } + } - private bool? CheckFamilies(Category cat1, Category cat2) - { - runes.TryGetValue(cat1, out Rune? rune1); - runes.TryGetValue(cat2, out Rune? rune2); - if(rune1 == null || rune2 == null) - { - return null; - } - return rune1.Family == rune2.Family; - } + private bool? CheckFamilies(Category cat1, Category cat2) + { + runes.TryGetValue(cat1, out Rune? rune1); + runes.TryGetValue(cat2, out Rune? rune2); + if (rune1 == null || rune2 == null) + { + return null; + } + return rune1.Family == rune2.Family; + } - private void UpdateMajorFamily(Category minor, bool expectedValue) - { - if(CheckFamilies(Category.Major, minor).GetValueOrDefault(expectedValue) == expectedValue) - { - runes.Remove(minor); - } - } - } + private void UpdateMajorFamily(Category cat, bool expectedValue) + { + if (CheckFamilies(Category.Major, cat).GetValueOrDefault(expectedValue) != expectedValue) + { + runes.Remove(cat); + } + } + } } diff --git a/Sources/Model/Skin.cs b/Sources/Model/Skin.cs index 04aa838..23bd218 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, string icon, float price) + { + this.name = name; + this.description = description; + Price = price; + } + public Skin(string name, string description, float price) { this.name = name; diff --git a/Sources/Shared/Shared.csproj b/Sources/Shared/Shared.csproj index 13dfccd..2c0bb3b 100644 --- a/Sources/Shared/Shared.csproj +++ b/Sources/Shared/Shared.csproj @@ -7,6 +7,7 @@ + all diff --git a/Sources/StubLib/StubLib.csproj b/Sources/StubLib/StubLib.csproj index 32d2dd1..a537131 100644 --- a/Sources/StubLib/StubLib.csproj +++ b/Sources/StubLib/StubLib.csproj @@ -7,6 +7,7 @@ + all diff --git a/Sources/Tests/ConsoleTests/ConsoleTests.csproj b/Sources/Tests/ConsoleTests/ConsoleTests.csproj index 48218dc..88e4e92 100644 --- a/Sources/Tests/ConsoleTests/ConsoleTests.csproj +++ b/Sources/Tests/ConsoleTests/ConsoleTests.csproj @@ -15,6 +15,7 @@ + all diff --git a/Sources/UnitTestsSQLiteInMemory/ChampionsDbTests.cs b/Sources/UnitTestsSQLiteInMemory/ChampionsDbTests.cs index b47022e..5c6b111 100644 --- a/Sources/UnitTestsSQLiteInMemory/ChampionsDbTests.cs +++ b/Sources/UnitTestsSQLiteInMemory/ChampionsDbTests.cs @@ -2,6 +2,7 @@ using EntityFrameworkLib; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using Model; +using System.Diagnostics; namespace UnitTestsSQLiteInMemory { @@ -20,9 +21,9 @@ namespace UnitTestsSQLiteInMemory 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" }; + ChampionEntity akali = new ChampionEntity { Name = "Akali", Bio = "Bio Akali", Icon = "Icon Akali", Class = ChampionClass.Assassin }; + ChampionEntity alistar = new ChampionEntity { Name = "Alistar", Bio = "Bio Alistar", Icon = "Icon Alistar", Class = ChampionClass.Support }; + ChampionEntity bard = new ChampionEntity { Name = "Bard", Bio = "Bio Bard", Icon = "Icon Bard", Class = ChampionClass.Support }; context.Champions.Add(akali); context.Champions.Add(alistar); @@ -54,9 +55,9 @@ namespace UnitTestsSQLiteInMemory //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" }; + ChampionEntity akali = new ChampionEntity { Name = "Akali", Bio = "Bio Akali", Icon = "Icon Akali", Class = ChampionClass.Assassin }; + ChampionEntity akshan = new ChampionEntity { Name = "Akshan", Bio = "Bio Akshan", Icon = "Icon Akshan", Class = ChampionClass.Fighter }; + ChampionEntity twitch = new ChampionEntity { Name = "Twitch", Bio = "Bio Twitch", Icon = "icon Twitch", Class = ChampionClass.Assassin }; context.Champions.Add(akali); context.Champions.Add(akshan); @@ -89,5 +90,40 @@ namespace UnitTestsSQLiteInMemory Assert.Equal(1, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count()); } } + + [Fact] + public void Delete_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 veigar = new ChampionEntity { Name = "Veigar", Bio = "Bio Veigar", Icon = "Icon Veigar", Class = ChampionClass.Fighter }; + ChampionEntity yone = new ChampionEntity { Name = "Yone", Bio = "Bio Yone", Icon = "Icon Yone", Class = ChampionClass.Assassin }; + ChampionEntity yasuo = new ChampionEntity { Name = "Yasuo", Bio = "Bio Yasuo", Icon = "icon Yasuo", Class = ChampionClass.Assassin }; + + context.Champions.Add(veigar); + context.Champions.Add(yone); + context.Champions.Add(yasuo); + + context.SaveChanges(); + + context.Champions.Remove(veigar); + context.Champions.Remove(yone); + context.Champions.Remove(yasuo); + + context.SaveChanges(); + } + } } } \ No newline at end of file diff --git a/Sources/UnitTestsSQLiteInMemory/UnitTestsSQLiteInMemory.csproj b/Sources/UnitTestsSQLiteInMemory/UnitTestsSQLiteInMemory.csproj index a1be2d9..41493d5 100644 --- a/Sources/UnitTestsSQLiteInMemory/UnitTestsSQLiteInMemory.csproj +++ b/Sources/UnitTestsSQLiteInMemory/UnitTestsSQLiteInMemory.csproj @@ -9,6 +9,7 @@ + diff --git a/Sources/Web_Api/ChampionDTO.cs b/Sources/Web_Api/ChampionDTO.cs index 722784d..4740598 100644 --- a/Sources/Web_Api/ChampionDTO.cs +++ b/Sources/Web_Api/ChampionDTO.cs @@ -7,6 +7,10 @@ namespace Web_Api public int Id { get; set; } public string Name { get; set; } public string Bio { get; set; } + public string Icon { get; set; } + public LargeImageDTO Image { get; set; } + public ChampionClass Class { get; set; } + public Champion toModel() { diff --git a/Sources/Web_Api/Controllers/ChampionsController.cs b/Sources/Web_Api/Controllers/ChampionsController.cs index 2cb8936..3904e62 100644 --- a/Sources/Web_Api/Controllers/ChampionsController.cs +++ b/Sources/Web_Api/Controllers/ChampionsController.cs @@ -1,18 +1,31 @@ -using Microsoft.AspNetCore.Http; +using EntityFrameworkLib; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; +using Microsoft.EntityFrameworkCore; using Model; using StubLib; using Web_Api.Mapper; +using static StubLib.StubData; namespace Web_Api.Controllers { [ApiController] [Route("api/[controller]")] - public class ChampionsController : Controller + public class ChampionsController : ControllerBase { + private StubData.ChampionsManager ChampionsManager { get; set; } = new StubData.ChampionsManager(new StubData()); + private readonly LolContext _context; + + public ChampionsController(LolContext context) + { + _context = context; + } + + //private StubData.ChampionsManager ChampionsManager { get; set; } = new StubData.ChampionsManager(new StubData()); + private readonly ILogger _logger; public ChampionsController(ILogger logger) @@ -20,21 +33,28 @@ namespace Web_Api.Controllers _logger = logger; } - [HttpGet] + [HttpGet("GET")] public async Task Get() { var list = await ChampionsManager.GetItems(0, await ChampionsManager.GetNbItems()); - return Ok(list.Select(champion => champion?.toDTO())); + return Ok(list.Select(rune => rune?.toDTO())); + //Faire en sorte d'avoir un ChampionDTO et pas ChampionENtity } - [HttpGet("name")] - public async Task GetById(string name) + [HttpGet("GETBYNAME")] + public async Task GetByName(string name) { var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null); - return Ok(championSelected.Select(c => c?.toDTO())); + if (championSelected.Count() == 0) + { + Console.WriteLine("Aucun champion ne correspond au nom { " + name + " } !"); + throw new Exception("Aucun champion ne correspond au nom { " + name + " } !"); + } + Console.WriteLine("Le champion { " + name + " } existe"); + return Ok(championSelected.Select(champion => champion?.toDTO())); } - [HttpPost("addChampion")] + [HttpPost("ADD")] public async Task AddChampion([FromBody] ChampionDTO champion) { var newChampion = champion.toModel(); @@ -47,7 +67,7 @@ namespace Web_Api.Controllers return Ok(); } - [HttpPut("updateChampion")] + [HttpPut("UPDATE")] public async Task UpdateChampion(string name, [FromBody] ChampionDTO champion) { var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null); @@ -67,7 +87,7 @@ namespace Web_Api.Controllers return Ok(); } - [HttpDelete("deleteChampion")] + [HttpDelete("DELETE")] public async Task DeleteChampion(string name) { var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null); diff --git a/Sources/Web_Api/Controllers/RunesController.cs b/Sources/Web_Api/Controllers/RunesController.cs index f8df9a0..2745d48 100644 --- a/Sources/Web_Api/Controllers/RunesController.cs +++ b/Sources/Web_Api/Controllers/RunesController.cs @@ -19,21 +19,27 @@ namespace Web_Api.Controllers _logger = logger; } - [HttpGet] + [HttpGet("GET")] 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) + [HttpGet("GETBYNAME")] + public async Task GetByName(string name) { - var runeSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null); - return Ok(runeSelected.Select(rune => rune?.toDTO())); + var runesSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null); + if (runesSelected.Count() == 0) + { + Console.WriteLine("Aucune rune ne correspond au nom { " + name + " } !"); + throw new Exception("Aucune rune ne correspond au nom { " + name + " } !"); + } + Console.WriteLine("La rune { " + name + " } existe"); + return Ok(runesSelected.Select(runes => runes?.toDTO())); } - [HttpPost("addRune")] + [HttpPost("ADD")] public async Task AddRune(RuneDTO rune) { var newRune = rune.toModel(); @@ -46,7 +52,7 @@ namespace Web_Api.Controllers return Ok(newRune); } - [HttpPut("updateRune")] + [HttpPut("UPDATE")] public async Task UpdateRune(string name, RuneDTO rune) { var runeSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null); @@ -66,7 +72,7 @@ namespace Web_Api.Controllers return Ok(); } - [HttpDelete("deleteRune")] + [HttpDelete("DELETE")] public async Task DeleteRune(string name) { var runeSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null); diff --git a/Sources/Web_Api/Controllers/SkinsController.cs b/Sources/Web_Api/Controllers/SkinsController.cs index c6d4bb1..63e9565 100644 --- a/Sources/Web_Api/Controllers/SkinsController.cs +++ b/Sources/Web_Api/Controllers/SkinsController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc; using StubLib; using Web_Api.Mapper; +using static StubLib.StubData; namespace Web_Api.Controllers { @@ -17,21 +18,27 @@ namespace Web_Api.Controllers _logger = logger; } - [HttpGet] + [HttpGet("GET")] 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) + [HttpGet("GETBYNAME")] + public async Task GetByName(string name) { - var skinSelected = await SkinsManager.GetItemsByName(name, 0, await SkinsManager.GetNbItemsByName(name), null); - return Ok(skinSelected.Select(skin => skin?.toDTO())); + var skinsSelected = await SkinsManager.GetItemsByName(name, 0, await SkinsManager.GetNbItemsByName(name), null); + if (skinsSelected.Count() == 0) + { + Console.WriteLine("Aucun skin ne correspond au nom { " + name + " } !"); + throw new Exception("Aucun skin ne correspond au nom { " + name + " } !"); + } + Console.WriteLine("Le skin { " + name + " } existe"); + return Ok(skinsSelected.Select(skins => skins?.toDTO())); } - [HttpPost("addSkin")] + [HttpPost("ADD")] public async Task AddSkin(SkinDTO skin) { var newSkin = skin.toModel(); @@ -44,7 +51,7 @@ namespace Web_Api.Controllers return Ok(newSkin); } - [HttpPut("updateSkin")] + [HttpPut("UPDATE")] public async Task UpdateChampion(string name, SkinDTO skin) { var skinSelected = await SkinsManager.GetItemsByName(name, 0, await SkinsManager.GetNbItemsByName(name), null); @@ -65,7 +72,7 @@ namespace Web_Api.Controllers return Ok(); } - [HttpDelete("deleteSkin")] + [HttpDelete("DELETE")] public async Task DeleteChampion(string name) { var skinSelected = await SkinsManager.GetItemsByName(name, 0, await SkinsManager.GetNbItemsByName(name), null); diff --git a/Sources/Web_Api/Controllers/WeatherForecastController.cs b/Sources/Web_Api/Controllers/WeatherForecastController.cs deleted file mode 100644 index de76cd4..0000000 --- a/Sources/Web_Api/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,33 +0,0 @@ -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/LargeImageDTO.cs b/Sources/Web_Api/LargeImageDTO.cs new file mode 100644 index 0000000..3be5194 --- /dev/null +++ b/Sources/Web_Api/LargeImageDTO.cs @@ -0,0 +1,17 @@ +using Model; +using System.Reflection.Metadata.Ecma335; +using System.Runtime.CompilerServices; + +namespace Web_Api +{ + public class LargeImageDTO + { + public int Id { get; set; } + public string Base64 { get; set; } + + public LargeImage toModel() + { + return new LargeImage(Base64); + } + } +} diff --git a/Sources/Web_Api/Program.cs b/Sources/Web_Api/Program.cs index 48863a6..e348fc8 100644 --- a/Sources/Web_Api/Program.cs +++ b/Sources/Web_Api/Program.cs @@ -1,11 +1,39 @@ +using EntityFrameworkLib; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.OpenApi.Models; +using Web_Api.Controllers; + var builder = WebApplication.CreateBuilder(args); +builder.Services.AddDbContext(options => + options.UseSqlite($"DataSource=projet.Champions.db")); + // 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(); +// Add versioning middleware +builder.Services.AddApiVersioning(options => +{ + // Add a default version + options.DefaultApiVersion = new ApiVersion(1, 0); + options.AssumeDefaultVersionWhenUnspecified = true; + options.ReportApiVersions = true; +}); + +//builder.Services.AddEndpointsApiExplorer(); +//builder.Services.AddSwaggerGen(); + +// Add Swagger +builder.Services.AddSwaggerGen(c => +{ + // Add version 1 documentation + c.SwaggerDoc("v1", new OpenApiInfo { Title = "API_LOL", Version = "v1" }); + + // Add version 2 documentation + c.SwaggerDoc("v2", new OpenApiInfo { Title = "API_LOL", Version = "v2" }); +}); var app = builder.Build(); @@ -13,13 +41,38 @@ var app = builder.Build(); if (app.Environment.IsDevelopment()) { app.UseSwagger(); - app.UseSwaggerUI(); + //app.UseSwaggerUI(); + app.UseSwaggerUI(c => + { + // Configure Swagger for version 1 + c.SwaggerEndpoint("/swagger/v1/swagger.json", "API_LOL v1"); + // Configure Swagger for version 2 + c.SwaggerEndpoint("/swagger/v2/swagger.json", "API_LOL v2"); + }); } app.UseHttpsRedirection(); - +app.UseRouting(); app.UseAuthorization(); -app.MapControllers(); +// Map version 1 to /api/v1 +app.Map("/api/v1", app => +{ + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); +}); + +// Map version 2 to /api/v2 +app.Map("/api/v2", app => +{ + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); +}); + +//app.MapControllers(); app.Run(); diff --git a/Sources/Web_Api/SwaggerOptions.cs b/Sources/Web_Api/SwaggerOptions.cs new file mode 100644 index 0000000..d6cb0f7 --- /dev/null +++ b/Sources/Web_Api/SwaggerOptions.cs @@ -0,0 +1,10 @@ +namespace Web_Api +{ + public class SwaggerOptions + { + public string JsonRoute { get; set; } + public string Description { get; set; } + public string UIEndpoint { get; set; } + public string Version { get; set; } + } +} diff --git a/Sources/Web_Api/WeatherForecast.cs b/Sources/Web_Api/WeatherForecast.cs deleted file mode 100644 index cf000f8..0000000 --- a/Sources/Web_Api/WeatherForecast.cs +++ /dev/null @@ -1,13 +0,0 @@ -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 index 9776754..b227040 100644 --- a/Sources/Web_Api/Web_Api.csproj +++ b/Sources/Web_Api/Web_Api.csproj @@ -7,10 +7,12 @@ + +