🚧 WIP
continuous-integration/drone/push Build is passing Details

pull/191/head
Alexis Drai 3 years ago
parent 3a49fe0e88
commit e6ba5f150e

@ -17,6 +17,7 @@
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\Utils\Utils\Utils.csproj" />
</ItemGroup>
</Project>

@ -1,4 +1,7 @@
using Data.EF.Players;
using Data.EF.Dice;
using Data.EF.Dice.Faces;
using Data.EF.Games;
using Data.EF.Players;
using Microsoft.EntityFrameworkCore;
using Model.Games;

@ -1,12 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Data.EF.Dice;
using Data.EF.Dice.Faces;
using Data.EF.Players;
namespace Data.EF.Games
{
public class TurnEntity
{
public Guid ID { get; set; }
public DateTime When { get; set; }
public PlayerEntity Player { get; set; }
public List<NumberDieEntity> NumberDice { get; set; }
public List<NumberFaceEntity> NumberFaces { get; set; }
public List<ImageDieEntity> ImageDice { get; set; }
public List<ImageFaceEntity> ImageFaces { get; set; }
public List<ColorDieEntity> ColorDice { get; set; }
public List<ColorFaceEntity> ColorFaces { get; set; }
}
}
}

@ -1,12 +1,95 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Data.EF.Dice;
using Data.EF.Dice.Faces;
using Data.EF.Players;
using Model.Dice;
using Model.Dice.Faces;
using Model.Games;
namespace Data.EF.Games
{
public static class TurnExtensions
{
public static Turn ToModel(this TurnEntity entity)
{
Dictionary<Die, Face> DiceNFaces = new();
DiceNFaces = Utils.Enumerables.FeedListsToDict(
DiceNFaces,
entity.ColorDice.ToModels() as List<Die>,
entity.ColorFaces.ToModels() as List<Face>
);
DiceNFaces = Utils.Enumerables.FeedListsToDict(
DiceNFaces,
entity.NumberDice.ToModels() as List<Die>,
entity.NumberFaces.ToModels() as List<Face>
);
DiceNFaces = Utils.Enumerables.FeedListsToDict(
DiceNFaces,
entity.ImageDice.ToModels() as List<Die>,
entity.ImageFaces.ToModels() as List<Face>
);
return Turn.CreateWithSpecifiedTime(
when: entity.When,
player: entity.Player.ToModel(),
diceNFaces: DiceNFaces
);
}
public static IEnumerable<Turn> ToModels(this IEnumerable<TurnEntity> entities)
{
return entities.Select(entity => entity.ToModel());
}
public static TurnEntity ToEntity(this Turn model)
{
List<NumberDieEntity> NumberDiceEntities = new();
List<ColorDieEntity> ColorDiceEntities = 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)
{
if (kvp.Key.GetType() == typeof(NumberDie))
{
NumberDiceEntities.Add((kvp.Key as NumberDie).ToEntity());
NumberFaceEntities.Add((kvp.Value as NumberFace).ToEntity());
}
if (kvp.Key.GetType() == typeof(ImageDie))
{
ImageDiceEntities.Add((kvp.Key as ImageDie).ToEntity());
ImageFaceEntities.Add((kvp.Value as ImageFace).ToEntity());
}
if (kvp.Key.GetType() == typeof(ColorDie))
{
ColorDiceEntities.Add((kvp.Key as ColorDie).ToEntity());
ColorFaceEntities.Add((kvp.Value as ColorFace).ToEntity());
}
}
return new TurnEntity()
{
When = model.When,
Player = model.Player.ToEntity(),
NumberDice = NumberDiceEntities,
NumberFaces = NumberFaceEntities,
ColorDice = ColorDiceEntities,
ColorFaces = ColorFaceEntities,
ImageDice = ImageDiceEntities,
ImageFaces = ImageFaceEntities
};
}
public static IEnumerable<TurnEntity> ToEntities(this IEnumerable<Turn> models)
{
return models.Select(model => model.ToEntity());
}
}
}
}

@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{953D2D67-BCE7-412C-B7BB-7C63B5592359}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Data", "Data\Data.csproj", "{E9683741-E603-4ED3-8088-4099D67FCA6D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Data", "Data\Data.csproj", "{E9683741-E603-4ED3-8088-4099D67FCA6D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "Utils\Utils\Utils.csproj", "{9300910D-9D32-4C79-8868-67D0ED56E2F3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -29,6 +31,10 @@ Global
{E9683741-E603-4ED3-8088-4099D67FCA6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E9683741-E603-4ED3-8088-4099D67FCA6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E9683741-E603-4ED3-8088-4099D67FCA6D}.Release|Any CPU.Build.0 = Release|Any CPU
{9300910D-9D32-4C79-8868-67D0ED56E2F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9300910D-9D32-4C79-8868-67D0ED56E2F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9300910D-9D32-4C79-8868-67D0ED56E2F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9300910D-9D32-4C79-8868-67D0ED56E2F3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -14,7 +14,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{953D2D67-BCE7-412C-B7BB-7C63B5592359}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Data", "Data\Data.csproj", "{E9683741-E603-4ED3-8088-4099D67FCA6D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Data", "Data\Data.csproj", "{E9683741-E603-4ED3-8088-4099D67FCA6D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "Utils\Utils\Utils.csproj", "{9300910D-9D32-4C79-8868-67D0ED56E2F3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -38,6 +40,10 @@ Global
{E9683741-E603-4ED3-8088-4099D67FCA6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E9683741-E603-4ED3-8088-4099D67FCA6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E9683741-E603-4ED3-8088-4099D67FCA6D}.Release|Any CPU.Build.0 = Release|Any CPU
{9300910D-9D32-4C79-8868-67D0ED56E2F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9300910D-9D32-4C79-8868-67D0ED56E2F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9300910D-9D32-4C79-8868-67D0ED56E2F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9300910D-9D32-4C79-8868-67D0ED56E2F3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -0,0 +1,22 @@
namespace Utils
{
public static class Enumerables
{
public static Dictionary<K, V> FromListsToDict<K, V>(List<K> keys, List<V> values)
{
return keys.Zip(values, (k, v) => new { k, v })
.ToDictionary(x => x.k, x => x.v);
}
public static Dictionary<K, V> FeedListsToDict<K, V>(Dictionary<K, V> kvps, List<K> keys, List<V> values)
{
Dictionary<K, V> additions = FromListsToDict(keys, values);
foreach (var kv in additions)
{
kvps.Add(kv.Key, kv.Value);
}
return kvps;
}
}
}

@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>
Loading…
Cancel
Save