diff --git a/.vs/LolProject/v17/.suo b/.vs/LolProject/v17/.suo index cb24cbd..d1429b7 100644 Binary files a/.vs/LolProject/v17/.suo and b/.vs/LolProject/v17/.suo differ diff --git a/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db b/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db index 2553478..f1405c5 100644 Binary files a/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db and b/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db differ diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs index dbd29c1..166bf36 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs @@ -13,13 +13,17 @@ namespace MyFlib [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } - [MaxLength(255)] + [Required] + [MaxLength(64)] public string Name { get; set; } + [Required] [MaxLength(255)] public string Bio { get; set; } public string Icon { get; set; } - public string Image { get; set; } + public LargeImageEntity Image { get; set; } + [Required] public ChampionClassEntity Class { get; set; } + public ICollection Skills { get; set; } } } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs new file mode 100644 index 0000000..8492da0 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyFlib +{ + public class LargeImageEntity + { + [Key] + public string Base64 { get; set; } + + } +} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkillEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkillEntity.cs new file mode 100644 index 0000000..fa87c23 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkillEntity.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyFlib +{ + public class SkillEntity + { + [Key] + [MaxLength(256)] + public string Name { get; set; } + + [Required] + [MaxLength(500)] + public string Description { get; set; } + + [Required] + public SkillTypeEntity Type { get; set; } + + } +} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs new file mode 100644 index 0000000..772e162 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyFlib +{ + 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; } + public LargeImageEntity Image { get; set; } + + } +} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/enums/ChampionClassEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/ChampionClassEntity.cs similarity index 100% rename from src/EntityFramework_LoL/Sources/MyFlib/enums/ChampionClassEntity.cs rename to src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/ChampionClassEntity.cs diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/SkillTypeEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/SkillTypeEntity.cs new file mode 100644 index 0000000..73c36e5 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/SkillTypeEntity.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyFlib +{ + public enum SkillTypeEntity + { + Unknown, + Basic, + Passive, + Ultimate + } +} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs index 5ff7132..abe8c71 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs @@ -10,6 +10,9 @@ namespace MyFlib public class LolDbContext : DbContext { public DbSet Champions { get; set; } + public DbSet Skills { get; set; } + public DbSet Skins { get; set; } + public DbSet Images { get; set; } public LolDbContext() { } @@ -28,12 +31,27 @@ namespace MyFlib modelBuilder.Entity().HasKey(e => e.Id); modelBuilder.Entity().Property(e => e.Id).ValueGeneratedOnAdd(); modelBuilder.Entity().HasData( - new ChampionEntity { Id = Guid.Parse("{4422C524-B2CB-43EF-8263-990C3CEA7CAE}"), Name = "Akali", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", Image = "" }, - new ChampionEntity { Id = Guid.Parse("{A4F84D92-C20F-4F2D-B3F9-CA00EF556E72}"), Name = "Aatrox", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", Image = "" }, - new ChampionEntity { Id = Guid.Parse("{AE5FE535-F041-445E-B570-28B75BC78CB9}"), Name = "Ahri", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = "" }, - new ChampionEntity { Id = Guid.Parse("{3708dcfd-02a1-491e-b4f7-e75bf274cf23}"), Name = "Akshan", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", Image = "" }, - new ChampionEntity { Id = Guid.Parse("{7f7746fa-b1cb-49da-9409-4b3e6910500e}"), Name = "Bard", Class = ChampionClassEntity.Support, Bio = "", Icon = "", Image = "" }, - new ChampionEntity { Id = Guid.Parse("{36ad2a82-d17b-47de-8a95-6e154a7df557}"), Name = "Alistar", Class = ChampionClassEntity.Tank, Bio = "", Icon = "", Image = "" } + new ChampionEntity { Id = Guid.Parse("{4422C524-B2CB-43EF-8263-990C3CEA7CAE}"), Name = "Akali", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", Image = new LargeImageEntity { Base64 = "empty" } }, + new ChampionEntity { Id = Guid.Parse("{A4F84D92-C20F-4F2D-B3F9-CA00EF556E72}"), Name = "Aatrox", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", Image = new LargeImageEntity { Base64 = "empty" } }, + new ChampionEntity { Id = Guid.Parse("{AE5FE535-F041-445E-B570-28B75BC78CB9}"), Name = "Ahri", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = new LargeImageEntity { Base64 = "empty" } }, + new ChampionEntity { Id = Guid.Parse("{3708dcfd-02a1-491e-b4f7-e75bf274cf23}"), Name = "Akshan", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", Image = new LargeImageEntity { Base64 = "empty" } }, + new ChampionEntity { Id = Guid.Parse("{7f7746fa-b1cb-49da-9409-4b3e6910500e}"), Name = "Bard", Class = ChampionClassEntity.Support, Bio = "", Icon = "", Image = new LargeImageEntity { Base64 = "empty" } }, + new ChampionEntity { Id = Guid.Parse("{36ad2a82-d17b-47de-8a95-6e154a7df557}"), Name = "Alistar", Class = ChampionClassEntity.Tank, Bio = "", Icon = "", Image = new LargeImageEntity { Base64 = "empty" } } + ); + + modelBuilder.Entity().HasData( + new SkillEntity { Name = "Boule de feu", Description = "Fire!", Type = SkillTypeEntity.Basic }, + new SkillEntity { Name = "White Star", Description = "Random damage", Type = SkillTypeEntity.Ultimate } + ); + + modelBuilder.Entity().HasData( + new LargeImageEntity { Base64 = "empty" }, + new LargeImageEntity { Base64 = "empty2" } + ); + + modelBuilder.Entity().HasData( + new SkinEntity { Name = "Yone fleur spirituelle", Description = "Spirit Blossom", Icon = "empty", Price = 975, Image = new LargeImageEntity { Base64 = "empty" } }, + new SkinEntity { Name = "Yasuo Lune de sang", Description = "Blood Moon", Icon = "empty", Price = 975, Image = new LargeImageEntity { Base64 = "empty" } } ); } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Program.cs b/src/EntityFramework_LoL/Sources/MyFlib/Program.cs index 0da5a3c..00d8f3d 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Program.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Program.cs @@ -1,20 +1,25 @@ // See https://aka.ms/new-console-template for more information using MyFlib; +using static System.Console; using (var context = new LolDbContext()) { foreach (var c in context.Champions) { - Console.WriteLine($"{c.Name} - {c.Class}"); + WriteLine($"{c.Name} - {c.Class}"); } - Console.WriteLine("\nWith new Champions :\n"); + WriteLine("\nWith new Champions :\n"); DataSeeder.SeedData(context); foreach (var c in context.Champions) { - Console.WriteLine($"{c.Name} - {c.Class}"); + WriteLine($"{c.Name} - {c.Class}"); + foreach (var s in c.Skills) + { + WriteLine($"\t\t{s.Name} - {s.Description}"); + } } context.SaveChangesAsync(); // or context.SaveChangesAsync diff --git a/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs b/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs index fd66059..ed24a8f 100644 --- a/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs +++ b/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs @@ -19,7 +19,11 @@ namespace UT_EF ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", Image = "" }; ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = "" }; - context.Champions.AddRange(sylas, hecarim, yuumi); + // test contrainte + ChampionEntity errorName = new ChampionEntity { Name = "c1832f35-f909-422d-a1fb-e0b79a62f562-fa7c5fe2-89b7-432e-9e0f-a5736445b381-3f75c0f8-de2e-4cf4-82d2-3d24411f6422-6b7e9196-3664-4813-b971-e9cc08a4b255-c1832f35-f909-422d-a1fb-e0b79a62f562-fa7c5fe2-89b7-432e-9e0f-a5736445b381-3f75c0f8-de2e-4cf4-82d2-3d24411f6422-6b7e9196-3664-4813-b971-e9cc08a4b255" + , Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = "" }; + + context.Champions.AddRange(sylas, hecarim, yuumi, errorName); context.SaveChanges(); }