Merge pull request '🐛 ♻️ Fix up dice and faces (EF)' (#189) from fixup-dice-entities into main
continuous-integration/drone/push Build is passing Details

Reviewed-on: #189
pull/190/head
Alexis Drai 2 years ago
commit 3a49fe0e88

@ -11,31 +11,31 @@ namespace Data.EF.Dice
/* /*
* creating an array of faces model * creating an array of faces model
*/ */
ColorFace[] faces= new ColorFace[clrDieEntity.Faces.Count-1]; ColorFace[] faces = new ColorFace[clrDieEntity.Faces.Count - 1];
List<ColorFace> clrFacesList = (List<ColorFace>)ColorFaceExtensions.ToModels(clrDieEntity.Faces); List<ColorFace> clrFacesList = clrDieEntity.Faces.ToModels().ToList();
clrFacesList.CopyTo(faces, 1); clrFacesList.CopyTo(faces, 1);
/* /*
* creating the die * creating the die
*/ */
ColorDie die = new (ColorFaceExtensions.ToModel(clrDieEntity.Faces.ElementAt(0)), faces); ColorDie die = new(clrDieEntity.Faces.ElementAt(0).ToModel(), faces);
return die; return die;
} }
public static IEnumerable<ColorDie> ToModels(this IEnumerable<ColorDieEntity> entities) public static IEnumerable<ColorDie> ToModels(this IEnumerable<ColorDieEntity> entities)
{ {
return entities.Select(entity => ToModel(entity)); return entities.Select(entity => entity.ToModel());
} }
public static ColorDieEntity ToEntity(this ColorDie model) public static ColorDieEntity ToEntity(this ColorDie model)
{ {
var entity = new ColorDieEntity(); 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; return entity;
} }
public static IEnumerable<ColorFaceEntity> ToEntities(this IEnumerable<ColorFace> models) public static IEnumerable<ColorDieEntity> ToEntities(this IEnumerable<ColorDie> models)
{ {
return models.Select(model => model.ToEntity()); return models.Select(model => model.ToEntity());
} }

@ -13,15 +13,16 @@ namespace Data.EF.Dice.Faces
public byte R { get; set; } public byte R { get; set; }
public byte G { get; set; } public byte G { get; set; }
public byte B { get; set; } public byte B { get; set; }
[ForeignKey("ColorDieFK")] [ForeignKey("ColorDieFK")]
public ColorDie ColorDie { get; set; } public ColorDie ColorDie { get; set; }
public void SetValue(Color c) public void SetValue(Color c)
{ {
A= c.A; A = c.A;
R= c.R; R = c.R;
G= c.G; G = c.G;
B= c.B; B = c.B;
} }
} }
} }

@ -12,7 +12,7 @@ namespace Data.EF.Dice.Faces
{ {
public static ColorFace ToModel(this ColorFaceEntity clrFaceEntity) 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; return colorFace;
} }
@ -23,7 +23,7 @@ namespace Data.EF.Dice.Faces
public static ColorFaceEntity ToEntity(this ColorFace model) 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<ColorFaceEntity> ToEntities(this IEnumerable<ColorFace> models) public static IEnumerable<ColorFaceEntity> ToEntities(this IEnumerable<ColorFace> models)

@ -12,6 +12,7 @@ namespace Data.EF.Dice.Faces
{ {
public Guid ID { get; set; } public Guid ID { get; set; }
public string Value { get; set; } public string Value { get; set; }
[ForeignKey("ImgDieFK")] [ForeignKey("ImgDieFK")]
public ImageDie ImageDie { get; set; } public ImageDie ImageDie { get; set; }
} }

@ -23,7 +23,7 @@ namespace Data.EF.Dice.Faces
public static ImageFaceEntity ToEntity(this ImageFace model) public static ImageFaceEntity ToEntity(this ImageFace model)
{ {
return new ImageFaceEntity() { Value = model.Value.ToString() }; return new ImageFaceEntity() { Value = model.StringValue };
} }
public static IEnumerable<ImageFaceEntity> ToEntities(this IEnumerable<ImageFace> models) public static IEnumerable<ImageFaceEntity> ToEntities(this IEnumerable<ImageFace> models)

@ -12,6 +12,7 @@ namespace Data.EF.Dice.Faces
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public int Value { get; set; } public int Value { get; set; }
[ForeignKey("NumDieFK")] [ForeignKey("NumDieFK")]
public NumberDie NumberDie { get; set; } public NumberDie NumberDie { get; set; }
} }

@ -12,14 +12,14 @@ namespace Data.EF.Dice
* creating an array of faces model * creating an array of faces model
*/ */
ImageFace[] faces = new ImageFace[clrDieEntity.Faces.Count - 1]; ImageFace[] faces = new ImageFace[clrDieEntity.Faces.Count - 1];
List<ImageFace> clrFacesList = (List<ImageFace>)ImageFaceExtensions.ToModels(clrDieEntity.Faces); List<ImageFace> clrFacesList = clrDieEntity.Faces.ToModels().ToList();
clrFacesList.CopyTo(faces, 1); clrFacesList.CopyTo(faces, 1);
/* /*
* creating the die * creating the die
*/ */
ImageDie die = new( ImageFaceExtensions.ToModel(clrDieEntity.Faces.ElementAt(0)), faces); ImageDie die = new(clrDieEntity.Faces.ElementAt(0).ToModel(), faces);
return die; return die;
} }
@ -32,7 +32,7 @@ namespace Data.EF.Dice
public static ImageDieEntity ToEntity(this ImageDie model) public static ImageDieEntity ToEntity(this ImageDie model)
{ {
var entity = new ImageDieEntity(); 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; return entity;
} }

@ -17,13 +17,13 @@ namespace Data.EF.Dice
* creating an array of faces model * creating an array of faces model
*/ */
NumberFace[] faces = new NumberFace[clrDieEntity.Faces.Count - 1]; NumberFace[] faces = new NumberFace[clrDieEntity.Faces.Count - 1];
List<NumberFace> clrFacesList = (List<NumberFace>)NumberFaceExtensions.ToModels(clrDieEntity.Faces); List<NumberFace> clrFacesList = clrDieEntity.Faces.ToModels().ToList();
clrFacesList.CopyTo(faces, 1); clrFacesList.CopyTo(faces, 1);
/* /*
* creating the die * creating the die
*/ */
NumberDie die = new(NumberFaceExtensions.ToModel(clrDieEntity.Faces.ElementAt(0)), faces); NumberDie die = new(clrDieEntity.Faces.ElementAt(0).ToModel(), faces);
return die; return die;
} }
@ -33,14 +33,14 @@ namespace Data.EF.Dice
return entities.Select(entity => ToModel(entity)); return entities.Select(entity => ToModel(entity));
} }
public static ColorDieEntity ToEntity(this ColorDie model) public static NumberDieEntity ToEntity(this NumberDie model)
{ {
var entity = new ColorDieEntity(); var entity = new NumberDieEntity();
foreach (var face in model.Faces) { entity.Faces.Add(ColorFaceExtensions.ToEntity((ColorFace)face)); } foreach (var face in model.Faces) { entity.Faces.Add(((NumberFace)face).ToEntity()); }
return entity; return entity;
} }
public static IEnumerable<ColorFaceEntity> ToEntities(this IEnumerable<ColorFace> models) public static IEnumerable<NumberDieEntity> ToEntities(this IEnumerable<NumberDie> models)
{ {
return models.Select(model => model.ToEntity()); return models.Select(model => model.ToEntity());
} }

@ -105,7 +105,7 @@ namespace Model.Games
Player.ToString()); Player.ToString());
foreach (Face face in this.diceNFaces.Values) foreach (Face face in this.diceNFaces.Values)
{ {
sb.Append(" " + face.ToString()); sb.Append(" " + face.StringValue);
} }
return sb.ToString(); return sb.ToString();

Loading…
Cancel
Save