@ -10,27 +10,59 @@ namespace Data.EF.Games
public static class TurnExtensions
public static class TurnExtensions
{
{
private static ( List < Die > , List < Face > ) ToModels ( ICollection < DieEntity > diceEntities , ICollection < FaceEntity > faceEntities )
{
List < Die > dice = new ( ) ;
List < Face > faces = new ( ) ;
foreach ( DieEntity dieEntity in diceEntities )
{
if ( dieEntity . GetType ( ) = = typeof ( NumberDieEntity ) )
{
dice . Add ( ( dieEntity as NumberDieEntity ) . ToModel ( ) ) ;
}
if ( dieEntity . GetType ( ) = = typeof ( ColorDieEntity ) )
{
dice . Add ( ( dieEntity as ColorDieEntity ) . ToModel ( ) ) ;
}
if ( dieEntity . GetType ( ) = = typeof ( ImageDieEntity ) )
{
dice . Add ( ( dieEntity as ImageDieEntity ) . ToModel ( ) ) ;
}
}
foreach ( FaceEntity faceEntity in faceEntities )
{
if ( faceEntity . GetType ( ) = = typeof ( NumberFaceEntity ) )
{
faces . Add ( ( faceEntity as NumberFaceEntity ) . ToModel ( ) ) ;
}
if ( faceEntity . GetType ( ) = = typeof ( ColorFaceEntity ) )
{
faces . Add ( ( faceEntity as ColorFaceEntity ) . ToModel ( ) ) ;
}
if ( faceEntity . GetType ( ) = = typeof ( ImageFaceEntity ) )
{
faces . Add ( ( faceEntity as ImageFaceEntity ) . ToModel ( ) ) ;
}
}
return ( dice , faces ) ;
}
public static Turn ToModel ( this TurnEntity entity )
public static Turn ToModel ( this TurnEntity entity )
{
{
Dictionary < Die , Face > DiceNFaces = new ( ) ;
Dictionary < Die , Face > DiceNFaces = new ( ) ;
DiceNFaces = Utils . Enumerables . FeedListsToDict (
List < Die > keysList ;
DiceNFaces ,
List < Face > valuesList ;
entity . ColorDice . ToModels ( ) as List < Die > ,
entity . ColorFaces . ToModels ( ) as List < Face >
) ;
DiceNFaces = Utils . Enumerables . FeedListsToDict (
( keysList , valuesList ) = ToModels ( entity . Dice , entity . Faces ) ;
DiceNFaces ,
entity . NumberDice . ToModels ( ) as List < Die > ,
entity . NumberFaces . ToModels ( ) as List < Face >
) ;
DiceNFaces = Utils . Enumerables . FeedListsToDict (
DiceNFaces = Utils . Enumerables . FeedListsToDict (
DiceNFaces ,
DiceNFaces ,
entity . ImageDice . ToModels ( ) as List < Die > ,
keysList ,
entity . ImageFaces . ToModels ( ) as List < Face >
valuesList
) ;
) ;
return Turn . CreateWithSpecifiedTime (
return Turn . CreateWithSpecifiedTime (
@ -48,29 +80,25 @@ namespace Data.EF.Games
public static TurnEntity ToEntity ( this Turn model )
public static TurnEntity ToEntity ( this Turn model )
{
{
List < NumberDieEntity > NumberDiceEntities = new ( ) ;
List < DieEntity > DiceEntities = new ( ) ;
List < ColorDieEntity > ColorDiceEntities = new ( ) ;
List < FaceEntity > FaceEntities = new ( ) ;
List < ImageDieEntity > ImageDiceEntities = new ( ) ;
List < NumberFaceEntity > NumberFaceEntities = new ( ) ;
List < ColorFaceEntity > ColorFaceEntities = new ( ) ;
List < ImageFaceEntity > ImageFaceEntities = new ( ) ;
foreach ( KeyValuePair < Die , Face > kvp in model . DiceNFaces )
foreach ( KeyValuePair < Die , Face > kvp in model . DiceNFaces )
{
{
if ( kvp . Key . GetType ( ) = = typeof ( NumberDie ) )
if ( kvp . Key . GetType ( ) = = typeof ( NumberDie ) )
{
{
Number DiceEntities. Add ( ( kvp . Key as NumberDie ) . ToEntity ( ) ) ;
DiceEntities. Add ( ( kvp . Key as NumberDie ) . ToEntity ( ) ) ;
Number FaceEntities. Add ( ( kvp . Value as NumberFace ) . ToEntity ( ) ) ;
FaceEntities. Add ( ( kvp . Value as NumberFace ) . ToEntity ( ) ) ;
}
}
if ( kvp . Key . GetType ( ) = = typeof ( ImageDie ) )
if ( kvp . Key . GetType ( ) = = typeof ( ImageDie ) )
{
{
Image DiceEntities. Add ( ( kvp . Key as ImageDie ) . ToEntity ( ) ) ;
DiceEntities. Add ( ( kvp . Key as ImageDie ) . ToEntity ( ) ) ;
Image FaceEntities. Add ( ( kvp . Value as ImageFace ) . ToEntity ( ) ) ;
FaceEntities. Add ( ( kvp . Value as ImageFace ) . ToEntity ( ) ) ;
}
}
if ( kvp . Key . GetType ( ) = = typeof ( ColorDie ) )
if ( kvp . Key . GetType ( ) = = typeof ( ColorDie ) )
{
{
Color DiceEntities. Add ( ( kvp . Key as ColorDie ) . ToEntity ( ) ) ;
DiceEntities. Add ( ( kvp . Key as ColorDie ) . ToEntity ( ) ) ;
Color FaceEntities. Add ( ( kvp . Value as ColorFace ) . ToEntity ( ) ) ;
FaceEntities. Add ( ( kvp . Value as ColorFace ) . ToEntity ( ) ) ;
}
}
}
}
@ -78,12 +106,8 @@ namespace Data.EF.Games
{
{
When = model . When ,
When = model . When ,
Player = model . Player . ToEntity ( ) ,
Player = model . Player . ToEntity ( ) ,
NumberDice = NumberDiceEntities ,
//Dice = DiceEntities,
NumberFaces = NumberFaceEntities ,
Faces = FaceEntities
ColorDice = ColorDiceEntities ,
ColorFaces = ColorFaceEntities ,
ImageDice = ImageDiceEntities ,
ImageFaces = ImageFaceEntities
} ;
} ;
}
}