diff --git a/Sources/ApiDePaul/Controllers/SkinController.cs b/Sources/ApiDePaul/Controllers/SkinController.cs index 8247d7e..fe4b0de 100644 --- a/Sources/ApiDePaul/Controllers/SkinController.cs +++ b/Sources/ApiDePaul/Controllers/SkinController.cs @@ -10,7 +10,7 @@ namespace ApiDePaul.Controllers [Route("[controller]")] public class SkinController : ControllerBase { - IDataManager donnees = new StubData(); + IDataManager donnees;// = new StubData(); private readonly ILogger _logger; diff --git a/Sources/ApiDePaul/laBdd.db b/Sources/ApiDePaul/laBdd.db index ff72a77..65b0561 100644 Binary files a/Sources/ApiDePaul/laBdd.db and b/Sources/ApiDePaul/laBdd.db differ diff --git a/Sources/BddTests/Program.cs b/Sources/BddTests/Program.cs index 1ff9cca..52b43ca 100644 --- a/Sources/BddTests/Program.cs +++ b/Sources/BddTests/Program.cs @@ -3,8 +3,8 @@ using Model; using TrucAuMilieu; -ChampionEntity c1 = new ChampionEntity("champion1", "il est beau", "imagepng.jpeg"); -Champion c2 = new Champion("joe"); +//ChampionEntity c1 = new ChampionEntity("champion1", "il est beau", "imagepng.jpeg"); +//Champion c2 = new Champion("joe"); Console.WriteLine("allo?"); var dataMgr = new DataBdd(); @@ -30,8 +30,8 @@ foreach (var champion in list1) }*/ -if (dataMgr.ChampionsMgr.DeleteItem(c2).Result) - Console.WriteLine("joe est mort."); +//if (dataMgr.ChampionsMgr.DeleteItem(c2).Result) +// Console.WriteLine("joe est mort."); foreach (var champion in dataMgr.ChampionsMgr.GetItems(0, dataMgr.ChampionsMgr.GetNbItems().Result).Result.ToList()) { Console.WriteLine(champion.Name); } diff --git a/Sources/BddTests/laBdd.db b/Sources/BddTests/laBdd.db index 960b991..65b0561 100644 Binary files a/Sources/BddTests/laBdd.db and b/Sources/BddTests/laBdd.db differ diff --git a/Sources/Model2/ChampionContext.cs b/Sources/Model2/ChampionContext.cs index 3e9419d..fd93be9 100644 --- a/Sources/Model2/ChampionContext.cs +++ b/Sources/Model2/ChampionContext.cs @@ -11,6 +11,7 @@ namespace LibEntityFramework public ChampionContext() { } public ChampionContext(DbContextOptions options) : base(options) { } public DbSet Champs { get; set; } + public DbSet Skins { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder options) { diff --git a/Sources/Model2/ChampionEntity.cs b/Sources/Model2/ChampionEntity.cs index 8bc240b..d81beda 100644 --- a/Sources/Model2/ChampionEntity.cs +++ b/Sources/Model2/ChampionEntity.cs @@ -13,12 +13,18 @@ namespace LibEntityFramework [Key] public string Name { get; set; } public string Bio { get; set; } + public string Class { get; set; } public string Icon { get; set; } - public ChampionEntity(string name, string bio, string icon) + public string Image { get; set; } + /*public List> Characteristics { get; set; } faudra les faire en base eux aussi + public List Skills { get; set; }*/ + /*public ChampionEntity(string nameid, string bio = "", string Class = "", string icon = "", string image = "") { - Name = name; + NameId = nameid; Bio = bio; + this.Class = Class; Icon = icon; - } + Image = image; + }*/ } } diff --git a/Sources/Model2/Migrations/20230317084952_migrationAvecSkin.Designer.cs b/Sources/Model2/Migrations/20230317084952_migrationAvecSkin.Designer.cs new file mode 100644 index 0000000..09e9f77 --- /dev/null +++ b/Sources/Model2/Migrations/20230317084952_migrationAvecSkin.Designer.cs @@ -0,0 +1,79 @@ +// +using LibEntityFramework; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace LibEntityFramework.Migrations +{ + [DbContext(typeof(ChampionContext))] + [Migration("20230317084952_migrationAvecSkin")] + partial class migrationAvecSkin + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("LibEntityFramework.ChampionEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Bio") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Class") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Image") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("Champs"); + }); + + modelBuilder.Entity("LibEntityFramework.SkinEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Champion") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Image") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Name"); + + b.ToTable("Skins"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/Model2/Migrations/20230317084952_migrationAvecSkin.cs b/Sources/Model2/Migrations/20230317084952_migrationAvecSkin.cs new file mode 100644 index 0000000..09f97dc --- /dev/null +++ b/Sources/Model2/Migrations/20230317084952_migrationAvecSkin.cs @@ -0,0 +1,59 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace LibEntityFramework.Migrations +{ + /// + public partial class migrationAvecSkin : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Class", + table: "Champs", + type: "TEXT", + nullable: false, + defaultValue: ""); + + migrationBuilder.AddColumn( + name: "Image", + table: "Champs", + type: "TEXT", + nullable: false, + defaultValue: ""); + + migrationBuilder.CreateTable( + name: "Skins", + columns: table => new + { + Name = table.Column(type: "TEXT", nullable: false), + Champion = table.Column(type: "TEXT", nullable: false), + Description = table.Column(type: "TEXT", nullable: false), + Icon = table.Column(type: "TEXT", nullable: false), + Image = table.Column(type: "TEXT", nullable: false), + Price = table.Column(type: "REAL", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Skins", x => x.Name); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Skins"); + + migrationBuilder.DropColumn( + name: "Class", + table: "Champs"); + + migrationBuilder.DropColumn( + name: "Image", + table: "Champs"); + } + } +} diff --git a/Sources/Model2/Migrations/ChampionContextModelSnapshot.cs b/Sources/Model2/Migrations/ChampionContextModelSnapshot.cs index a4bfb9c..0f82d9b 100644 --- a/Sources/Model2/Migrations/ChampionContextModelSnapshot.cs +++ b/Sources/Model2/Migrations/ChampionContextModelSnapshot.cs @@ -25,14 +25,51 @@ namespace LibEntityFramework.Migrations .IsRequired() .HasColumnType("TEXT"); + b.Property("Class") + .IsRequired() + .HasColumnType("TEXT"); + b.Property("Icon") .IsRequired() .HasColumnType("TEXT"); + b.Property("Image") + .IsRequired() + .HasColumnType("TEXT"); + b.HasKey("Name"); b.ToTable("Champs"); }); + + modelBuilder.Entity("LibEntityFramework.SkinEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Champion") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Image") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Name"); + + b.ToTable("Skins"); + }); #pragma warning restore 612, 618 } } diff --git a/Sources/Model2/SkinEntity.cs b/Sources/Model2/SkinEntity.cs new file mode 100644 index 0000000..5446e99 --- /dev/null +++ b/Sources/Model2/SkinEntity.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LibEntityFramework +{ + public class SkinEntity + { + [Key] + public string Name { get; set; } + public string Champion { get; set; } + public string Description { get; set; } + public string Icon { get; set; } + public string Image { get; set; } + public float Price { get; set; } + } +} diff --git a/Sources/Model2/laBdd.db b/Sources/Model2/laBdd.db index ef20381..65b0561 100644 Binary files a/Sources/Model2/laBdd.db and b/Sources/Model2/laBdd.db differ diff --git a/Sources/TrucAuMilieu/ChampionConvert.cs b/Sources/TrucAuMilieu/ChampionConvert.cs index e82875a..a8f1a74 100644 --- a/Sources/TrucAuMilieu/ChampionConvert.cs +++ b/Sources/TrucAuMilieu/ChampionConvert.cs @@ -10,7 +10,45 @@ namespace TrucAuMilieu { public static class ChampionConvert { - public static ChampionEntity ChampToEf(this Champion c) => new ChampionEntity(c.Name, c.Bio, c.Icon); - public static Champion EfToChamp(this ChampionEntity c) => new Champion(c.Name,ChampionClass.Tank,c.Icon,c.Icon,c.Bio); + public static ChampionEntity ChampToEf(this Champion c) + { + /*foreach(var sk in c.Skins) + { + faudrait faire avec les autres trucs + }*/ + return new ChampionEntity() + { + Name=c.Name, + Bio=c.Bio, + Class=c.Class.ToString(), + Icon=c.Icon, + Image=c.Image.ToString() + }; + } + public static Champion EfToChamp(this ChampionEntity c) + { + Champion champ = new Champion(c.Name); + var classes = Enum.GetNames(typeof(ChampionClass)); + if (classes.ToList().Contains(c.Class)) + { + champ.Class = (ChampionClass)Enum.Parse(typeof(ChampionClass), c.Class); + } + else + { + champ.Class = 0; + } + champ.Icon = c.Icon; + champ.Image = new LargeImage(c.Image); + champ.Bio = c.Bio; + /* + foreach (var s in c.Skills) + { + champ.AddSkill(s.DtoToSkill()); + } + champ.AddCharacteristics(c.Characteristics.ToArray()); + */ + return champ; + + } } } diff --git a/Sources/TrucAuMilieu/DataBdd.Skin.cs b/Sources/TrucAuMilieu/DataBdd.Skin.cs new file mode 100644 index 0000000..ee2181c --- /dev/null +++ b/Sources/TrucAuMilieu/DataBdd.Skin.cs @@ -0,0 +1,82 @@ +using LibEntityFramework; +using Model; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TrucAuMilieu +{ + public partial class DataBdd + { + public ChampionContext ct = new ChampionContext(); + public class SkinManager : ISkinsManager + { + private readonly DataBdd parent; + public SkinManager(DataBdd parent) + => this.parent = parent; + public async Task AddItem(Skin? item) + { + await parent.ct.AddAsync(item.SkinToEf()); + await parent.contextCh.SaveChangesAsync(); + Debug.WriteLine("skin ajouté"); + return item; + } + + public Task DeleteItem(Skin? item) + { + throw new NotImplementedException(); + } + + public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + //requete sur les champions avec des arguments (genre la pagination est possible, et y'a le descending et tout) + { + if (orderingPropertyName != null) + { + if (descending) + { + return await Task.FromResult(parent.ct.Skins.OrderByDescending(s => typeof(SkinEntity).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(sk => sk.EfToSkin())); + } + else + { + var pap = await Task.FromResult(parent.ct.Skins.OrderBy(c => typeof(SkinEntity).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(sk => sk.EfToSkin())); + return pap; + } + } + else + { + var pap2 = await Task.FromResult(parent.ct.Skins.Skip(index * count).Take(count).Select(sk => sk.EfToSkin())); + return pap2; + } + } + + public Task> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + public Task GetNbItems() => Task.FromResult(parent.ct.Skins.Count()); + + public Task GetNbItemsByChampion(Champion? champion) + { + throw new NotImplementedException(); + } + + public Task GetNbItemsByName(string substring) + { + throw new NotImplementedException(); + } + + public Task UpdateItem(Skin? oldItem, Skin? newItem) + { + throw new NotImplementedException(); + } + } + } +} diff --git a/Sources/TrucAuMilieu/DataBdd.cs b/Sources/TrucAuMilieu/DataBdd.cs index 4a31b59..5b38195 100644 --- a/Sources/TrucAuMilieu/DataBdd.cs +++ b/Sources/TrucAuMilieu/DataBdd.cs @@ -13,6 +13,7 @@ namespace TrucAuMilieu public DataBdd() { ChampionsMgr = new ChampionsManager(this); + SkinsMgr = new SkinManager(this); } public IChampionsManager ChampionsMgr { get; } diff --git a/Sources/TrucAuMilieu/SkinConvert.cs b/Sources/TrucAuMilieu/SkinConvert.cs new file mode 100644 index 0000000..5ba666b --- /dev/null +++ b/Sources/TrucAuMilieu/SkinConvert.cs @@ -0,0 +1,32 @@ +using LibEntityFramework; +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TrucAuMilieu +{ + public static class SkinConvert + { + public static SkinEntity SkinToEf(this Skin s) + { + return new SkinEntity() + { + Name = s.Name, + Champion = s.Champion.Name, + Description = s.Description, + Icon = s.Icon, + Image = s.Image.ToString(), + Price = s.Price + }; + } + public static Skin EfToSkin(this SkinEntity s) + { + var dataMgr = new DataBdd(); + Champion c = dataMgr.ChampionsMgr.GetItemsByName(s.Champion, 0, 1).Result.First(); + return new Skin(s.Name,c,s.Price,s.Icon,s.Image,s.Description); + } + } +} \ No newline at end of file