diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/enums/ChampionClassMapper.cs b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/enums/ChampionClassMapper.cs index c0c52ed..9f4d332 100644 --- a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/enums/ChampionClassMapper.cs +++ b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/enums/ChampionClassMapper.cs @@ -7,11 +7,74 @@ namespace ApiLol.Mapper { public static ChampionClassDto ToDto(this ChampionClass championClass) { - return (ChampionClassDto) championClass; + if (championClass == ChampionClass.Unknown) + { + return ChampionClassDto.Unknown; + } + if (championClass == ChampionClass.Assassin) + { + return ChampionClassDto.Assassin; + } + if (championClass == ChampionClass.Fighter) + { + return ChampionClassDto.Fighter; + } + if (championClass == ChampionClass.Mage) + { + return ChampionClassDto.Mage; + } + if (championClass == ChampionClass.Marksman) + { + return ChampionClassDto.Marksman; + } + if (championClass == ChampionClass.Support) + { + return ChampionClassDto.Support; + } + if (championClass == ChampionClass.Tank) + { + return ChampionClassDto.Tank; + } + else + { + return ChampionClassDto.Unknown; + } + } public static ChampionClass ToModel(this ChampionClassDto championClass) - { - return (ChampionClass) championClass; + { + if (championClass == ChampionClassDto.Unknown) + { + return ChampionClass.Unknown; + } + if (championClass == ChampionClassDto.Assassin) + { + return ChampionClass.Assassin; + } + if (championClass == ChampionClassDto.Fighter) + { + return ChampionClass.Fighter; + } + if (championClass == ChampionClassDto.Mage) + { + return ChampionClass.Mage; + } + if (championClass == ChampionClassDto.Marksman) + { + return ChampionClass.Marksman; + } + if (championClass == ChampionClassDto.Support) + { + return ChampionClass.Support; + } + if (championClass == ChampionClassDto.Tank) + { + return ChampionClass.Tank; + } + else + { + return ChampionClass.Unknown; + } } } } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db b/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db index f1405c5..9ff30fa 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/DataSeeder.cs b/src/EntityFramework_LoL/Sources/MyFlib/DataSeeder.cs index eeb743a..8f18894 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/DataSeeder.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/DataSeeder.cs @@ -9,10 +9,12 @@ namespace MyFlib public static class DataSeeder { public static void SeedData(LolDbContext context) - { - ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", Image = "" }; - ChampionEntity nasus = new ChampionEntity { Name = "Nasus", Class = ChampionClassEntity.Tank, Bio = "", Icon = "", Image = "" }; - ChampionEntity ashe = new ChampionEntity { Name = "Ashe", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", Image = "" }; + { + var image1 = new LargeImageEntity { Id = 1, Base64 = "empty" }; + + ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity nasus = new ChampionEntity { Name = "Nasus", Class = ChampionClassEntity.Tank, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity ashe = new ChampionEntity { Name = "Ashe", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", ImageId = 1 }; context.AddRange(hecarim, nasus, ashe); diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs index a7755f7..19c0183 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs @@ -20,10 +20,13 @@ namespace MyFlib [MaxLength(255)] public string Bio { get; set; } public string Icon { get; set; } - public string Image { get; set; } [Required] public ChampionClassEntity Class { get; set; } public ICollection Skills { get; set; } + public LargeImageEntity Image { get; set; } + + [ForeignKey("Image")] + public int ImageId { get; set; } } } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs index 6fa04cf..5882826 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs @@ -11,7 +11,7 @@ namespace MyFlib { [Key] - public int ImageId { get; set; } + public int Id { get; set; } public string Base64 { get; set; } } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/Rune.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/Rune.cs new file mode 100644 index 0000000..5690737 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/Rune.cs @@ -0,0 +1,26 @@ +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 MyFlib +{ + public class Rune + { + [Key] + [MaxLength(256)] + public string Name { get; set; } + + [Required] + [MaxLength(500)] + public string Description { get; set; } + public SkillTypeEntity SkillType { get; set; } + public LargeImageEntity Image { get; set; } + + [ForeignKey("Image")] + public int ImageId { get; set; } + } +} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs index 772e162..c16b4c8 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs @@ -1,6 +1,7 @@ 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; @@ -21,5 +22,8 @@ namespace MyFlib public float Price { get; set; } public LargeImageEntity Image { get; set; } + [ForeignKey("Image")] + public int ImageId { get; set; } + } } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/RuneFamilyEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/RuneFamilyEntity.cs new file mode 100644 index 0000000..f76c708 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/RuneFamilyEntity.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyFlib.Entities.enums +{ + enum RuneFamilyEntity + { + Unknown, + Precision, + Domination + } +} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs index e507575..3291f49 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs @@ -27,22 +27,21 @@ namespace MyFlib } protected override void OnModelCreating(ModelBuilder modelBuilder) { - var image1 = new LargeImageEntity { ImageId = 1, Base64 = "image1" }; - var image2 = new LargeImageEntity { ImageId = 2, Base64 = "image2" }; + var image1 = new LargeImageEntity { Id = 1, Base64 = "empty" }; + var image2 = new LargeImageEntity { Id = 2, Base64 = " " }; modelBuilder.Entity().HasData(image1, image2); - modelBuilder.Entity().Property("ImageId"); - modelBuilder.Entity().HasKey(e => e.Id); + modelBuilder.Entity().Property(e => e.Id).ValueGeneratedOnAdd(); modelBuilder.Entity().HasData( - new { Id = Guid.Parse("{4422C524-B2CB-43EF-8263-990C3CEA7CAE}"), Name = "Akali", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", Image = "empty" }, - new { Id = Guid.Parse("{A4F84D92-C20F-4F2D-B3F9-CA00EF556E72}"), Name = "Aatrox", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", Image = "empty" }, - new { Id = Guid.Parse("{AE5FE535-F041-445E-B570-28B75BC78CB9}"), Name = "Ahri", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = "empty" }, - new { Id = Guid.Parse("{3708dcfd-02a1-491e-b4f7-e75bf274cf23}"), Name = "Akshan", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", Image = "empty" }, - new { Id = Guid.Parse("{7f7746fa-b1cb-49da-9409-4b3e6910500e}"), Name = "Bard", Class = ChampionClassEntity.Support, Bio = "", Icon = "", Image = "empty" }, - new { Id = Guid.Parse("{36ad2a82-d17b-47de-8a95-6e154a7df557}"), Name = "Alistar", Class = ChampionClassEntity.Tank, Bio = "", Icon = "", Image = "empty" } + new { Id = Guid.Parse("{4422C524-B2CB-43EF-8263-990C3CEA7CAE}"), Name = "Akali", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = 1 }, + new { Id = Guid.Parse("{A4F84D92-C20F-4F2D-B3F9-CA00EF556E72}"), Name = "Aatrox", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", ImageId = 2 }, + new { Id = Guid.Parse("{AE5FE535-F041-445E-B570-28B75BC78CB9}"), Name = "Ahri", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", ImageId = 1 }, + new { Id = Guid.Parse("{3708dcfd-02a1-491e-b4f7-e75bf274cf23}"), Name = "Akshan", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", ImageId = 1 }, + new { Id = Guid.Parse("{7f7746fa-b1cb-49da-9409-4b3e6910500e}"), Name = "Bard", Class = ChampionClassEntity.Support, Bio = "", Icon = "", ImageId = 1 }, + new { Id = Guid.Parse("{36ad2a82-d17b-47de-8a95-6e154a7df557}"), Name = "Alistar", Class = ChampionClassEntity.Tank, Bio = "", Icon = "", ImageId = 1 } ); modelBuilder.Entity().HasData( diff --git a/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs b/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs index fd66059..723a3a6 100644 --- a/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs +++ b/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs @@ -15,10 +15,20 @@ namespace UT_EF using (var context = new LolDbContext(options)) { - ChampionEntity sylas = new ChampionEntity { Name = "Sylas", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", Image = "" }; - ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", Image = "" }; - ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = "" }; + ChampionEntity sylas = new ChampionEntity { Name = "Sylas", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", ImageId = 1 }; + + // 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 = "", + ImageId = 1 + }; context.Champions.AddRange(sylas, hecarim, yuumi); context.SaveChanges(); } @@ -39,9 +49,10 @@ namespace UT_EF using (var context = new LolDbContext(options)) { - ChampionEntity sylas = new ChampionEntity { Name = "Sylas", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", Image = "" }; - ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", Image = "" }; - ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = "" }; + + ChampionEntity sylas = new ChampionEntity { Name = "Sylas", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", ImageId = 1 }; context.Champions.AddRange(sylas, hecarim, yuumi); context.SaveChanges(); @@ -84,9 +95,10 @@ namespace UT_EF using (var context = new LolDbContext(options)) { - ChampionEntity sylas = new ChampionEntity { Name = "Sylas", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", Image = "" }; - ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", Image = "" }; - ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = "" }; + + ChampionEntity sylas = new ChampionEntity { Name = "Sylas", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", ImageId = 1 }; context.Champions.AddRange(sylas, hecarim, yuumi); context.SaveChanges();