From b760b6f905b92578d645e0f627343f931d1aa4a6 Mon Sep 17 00:00:00 2001 From: Alexis DRAI Date: Sat, 15 Oct 2022 20:13:53 +0200 Subject: [PATCH 1/2] :bug: --- Sources/Data/EF/Dice/ColorDieExtensions.cs | 2 +- Sources/Data/EF/Dice/NumberDieExtensions.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Data/EF/Dice/ColorDieExtensions.cs b/Sources/Data/EF/Dice/ColorDieExtensions.cs index ba44224..ed1d0ea 100644 --- a/Sources/Data/EF/Dice/ColorDieExtensions.cs +++ b/Sources/Data/EF/Dice/ColorDieExtensions.cs @@ -35,7 +35,7 @@ namespace Data.EF.Dice return entity; } - public static IEnumerable ToEntities(this IEnumerable models) + public static IEnumerable ToEntities(this IEnumerable models) { return models.Select(model => model.ToEntity()); } diff --git a/Sources/Data/EF/Dice/NumberDieExtensions.cs b/Sources/Data/EF/Dice/NumberDieExtensions.cs index ce49b2c..438fa51 100644 --- a/Sources/Data/EF/Dice/NumberDieExtensions.cs +++ b/Sources/Data/EF/Dice/NumberDieExtensions.cs @@ -33,14 +33,14 @@ namespace Data.EF.Dice return entities.Select(entity => ToModel(entity)); } - public static ColorDieEntity ToEntity(this ColorDie model) + public static NumberDieEntity ToEntity(this NumberDie model) { - var entity = new ColorDieEntity(); - foreach (var face in model.Faces) { entity.Faces.Add(ColorFaceExtensions.ToEntity((ColorFace)face)); } + var entity = new NumberDieEntity(); + foreach (var face in model.Faces) { entity.Faces.Add(((NumberFace)face).ToEntity()); } return entity; } - public static IEnumerable ToEntities(this IEnumerable models) + public static IEnumerable ToEntities(this IEnumerable models) { return models.Select(model => model.ToEntity()); } From 2c44df5e16ca18cadbe3722c170b94cf62f1580c Mon Sep 17 00:00:00 2001 From: Alexis DRAI Date: Sat, 15 Oct 2022 20:16:23 +0200 Subject: [PATCH 2/2] :recycle: Use extension features ImageDieExtensions.ToModel(entity) --> entity.ToModel() --- Sources/Data/EF/Dice/ColorDieExtensions.cs | 12 ++++++------ Sources/Data/EF/Dice/Faces/ColorFaceEntity.cs | 9 +++++---- Sources/Data/EF/Dice/Faces/ColorFaceExtensions.cs | 4 ++-- Sources/Data/EF/Dice/Faces/ImageFaceEntity.cs | 1 + Sources/Data/EF/Dice/Faces/ImageFaceExtensions.cs | 2 +- Sources/Data/EF/Dice/Faces/NumberFaceEntity.cs | 1 + Sources/Data/EF/Dice/ImageDieExtensions.cs | 6 +++--- Sources/Data/EF/Dice/NumberDieExtensions.cs | 4 ++-- Sources/Model/Games/Turn.cs | 2 +- 9 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Sources/Data/EF/Dice/ColorDieExtensions.cs b/Sources/Data/EF/Dice/ColorDieExtensions.cs index ed1d0ea..e3860d6 100644 --- a/Sources/Data/EF/Dice/ColorDieExtensions.cs +++ b/Sources/Data/EF/Dice/ColorDieExtensions.cs @@ -11,27 +11,27 @@ namespace Data.EF.Dice /* * creating an array of faces model */ - ColorFace[] faces= new ColorFace[clrDieEntity.Faces.Count-1]; - List clrFacesList = (List)ColorFaceExtensions.ToModels(clrDieEntity.Faces); + ColorFace[] faces = new ColorFace[clrDieEntity.Faces.Count - 1]; + List clrFacesList = clrDieEntity.Faces.ToModels().ToList(); clrFacesList.CopyTo(faces, 1); /* * creating the die */ - ColorDie die = new (ColorFaceExtensions.ToModel(clrDieEntity.Faces.ElementAt(0)), faces); - + ColorDie die = new(clrDieEntity.Faces.ElementAt(0).ToModel(), faces); + return die; } public static IEnumerable ToModels(this IEnumerable entities) { - return entities.Select(entity => ToModel(entity)); + return entities.Select(entity => entity.ToModel()); } public static ColorDieEntity ToEntity(this ColorDie model) { var entity = new ColorDieEntity(); - foreach (var face in model.Faces) { entity.Faces.Add(ColorFaceExtensions.ToEntity((ColorFace)face)); } + foreach (var face in model.Faces) { entity.Faces.Add(((ColorFace)face).ToEntity()); } return entity; } diff --git a/Sources/Data/EF/Dice/Faces/ColorFaceEntity.cs b/Sources/Data/EF/Dice/Faces/ColorFaceEntity.cs index dac1252..130dd53 100644 --- a/Sources/Data/EF/Dice/Faces/ColorFaceEntity.cs +++ b/Sources/Data/EF/Dice/Faces/ColorFaceEntity.cs @@ -13,15 +13,16 @@ namespace Data.EF.Dice.Faces public byte R { get; set; } public byte G { get; set; } public byte B { get; set; } + [ForeignKey("ColorDieFK")] public ColorDie ColorDie { get; set; } public void SetValue(Color c) { - A= c.A; - R= c.R; - G= c.G; - B= c.B; + A = c.A; + R = c.R; + G = c.G; + B = c.B; } } } diff --git a/Sources/Data/EF/Dice/Faces/ColorFaceExtensions.cs b/Sources/Data/EF/Dice/Faces/ColorFaceExtensions.cs index 465aa70..7b789f4 100644 --- a/Sources/Data/EF/Dice/Faces/ColorFaceExtensions.cs +++ b/Sources/Data/EF/Dice/Faces/ColorFaceExtensions.cs @@ -12,7 +12,7 @@ namespace Data.EF.Dice.Faces { public static ColorFace ToModel(this ColorFaceEntity clrFaceEntity) { - ColorFace colorFace = new (Color.FromArgb(clrFaceEntity.A, clrFaceEntity.R, clrFaceEntity.G, clrFaceEntity.B)); + ColorFace colorFace = new(Color.FromArgb(clrFaceEntity.A, clrFaceEntity.R, clrFaceEntity.G, clrFaceEntity.B)); return colorFace; } @@ -23,7 +23,7 @@ namespace Data.EF.Dice.Faces public static ColorFaceEntity ToEntity(this ColorFace model) { - return new ColorFaceEntity() { A=model.Value.A,R=model.Value.R,G=model.Value.G,B=model.Value.B }; + return new ColorFaceEntity() { A = model.Value.A, R = model.Value.R, G = model.Value.G, B = model.Value.B }; } public static IEnumerable ToEntities(this IEnumerable models) diff --git a/Sources/Data/EF/Dice/Faces/ImageFaceEntity.cs b/Sources/Data/EF/Dice/Faces/ImageFaceEntity.cs index a539bf2..bb821d8 100644 --- a/Sources/Data/EF/Dice/Faces/ImageFaceEntity.cs +++ b/Sources/Data/EF/Dice/Faces/ImageFaceEntity.cs @@ -12,6 +12,7 @@ namespace Data.EF.Dice.Faces { public Guid ID { get; set; } public string Value { get; set; } + [ForeignKey("ImgDieFK")] public ImageDie ImageDie { get; set; } } diff --git a/Sources/Data/EF/Dice/Faces/ImageFaceExtensions.cs b/Sources/Data/EF/Dice/Faces/ImageFaceExtensions.cs index c8aeb66..4eb9d53 100644 --- a/Sources/Data/EF/Dice/Faces/ImageFaceExtensions.cs +++ b/Sources/Data/EF/Dice/Faces/ImageFaceExtensions.cs @@ -23,7 +23,7 @@ namespace Data.EF.Dice.Faces public static ImageFaceEntity ToEntity(this ImageFace model) { - return new ImageFaceEntity() { Value = model.Value.ToString() }; + return new ImageFaceEntity() { Value = model.StringValue }; } public static IEnumerable ToEntities(this IEnumerable models) diff --git a/Sources/Data/EF/Dice/Faces/NumberFaceEntity.cs b/Sources/Data/EF/Dice/Faces/NumberFaceEntity.cs index ac3d7a2..3f27ef3 100644 --- a/Sources/Data/EF/Dice/Faces/NumberFaceEntity.cs +++ b/Sources/Data/EF/Dice/Faces/NumberFaceEntity.cs @@ -12,6 +12,7 @@ namespace Data.EF.Dice.Faces { public Guid Id { get; set; } public int Value { get; set; } + [ForeignKey("NumDieFK")] public NumberDie NumberDie { get; set; } } diff --git a/Sources/Data/EF/Dice/ImageDieExtensions.cs b/Sources/Data/EF/Dice/ImageDieExtensions.cs index a83d2ff..772470e 100644 --- a/Sources/Data/EF/Dice/ImageDieExtensions.cs +++ b/Sources/Data/EF/Dice/ImageDieExtensions.cs @@ -12,14 +12,14 @@ namespace Data.EF.Dice * creating an array of faces model */ ImageFace[] faces = new ImageFace[clrDieEntity.Faces.Count - 1]; - List clrFacesList = (List)ImageFaceExtensions.ToModels(clrDieEntity.Faces); + List clrFacesList = clrDieEntity.Faces.ToModels().ToList(); clrFacesList.CopyTo(faces, 1); /* * creating the die */ - ImageDie die = new( ImageFaceExtensions.ToModel(clrDieEntity.Faces.ElementAt(0)), faces); + ImageDie die = new(clrDieEntity.Faces.ElementAt(0).ToModel(), faces); return die; } @@ -32,7 +32,7 @@ namespace Data.EF.Dice public static ImageDieEntity ToEntity(this ImageDie model) { var entity = new ImageDieEntity(); - foreach (var face in model.Faces) { entity.Faces.Add(ImageFaceExtensions.ToEntity((ImageFace)face)); } + foreach (var face in model.Faces) { entity.Faces.Add(((ImageFace)face).ToEntity()); } return entity; } diff --git a/Sources/Data/EF/Dice/NumberDieExtensions.cs b/Sources/Data/EF/Dice/NumberDieExtensions.cs index 438fa51..a2fa363 100644 --- a/Sources/Data/EF/Dice/NumberDieExtensions.cs +++ b/Sources/Data/EF/Dice/NumberDieExtensions.cs @@ -17,13 +17,13 @@ namespace Data.EF.Dice * creating an array of faces model */ NumberFace[] faces = new NumberFace[clrDieEntity.Faces.Count - 1]; - List clrFacesList = (List)NumberFaceExtensions.ToModels(clrDieEntity.Faces); + List clrFacesList = clrDieEntity.Faces.ToModels().ToList(); clrFacesList.CopyTo(faces, 1); /* * creating the die */ - NumberDie die = new(NumberFaceExtensions.ToModel(clrDieEntity.Faces.ElementAt(0)), faces); + NumberDie die = new(clrDieEntity.Faces.ElementAt(0).ToModel(), faces); return die; } diff --git a/Sources/Model/Games/Turn.cs b/Sources/Model/Games/Turn.cs index a6e377b..e45df9a 100644 --- a/Sources/Model/Games/Turn.cs +++ b/Sources/Model/Games/Turn.cs @@ -105,7 +105,7 @@ namespace Model.Games Player.ToString()); foreach (Face face in this.diceNFaces.Values) { - sb.Append(" " + face.ToString()); + sb.Append(" " + face.StringValue); } return sb.ToString();