diff --git a/Sources/BowlingApp/BowlingApp.csproj b/Sources/BowlingApp/BowlingApp.csproj
index d267dee..9f13908 100644
--- a/Sources/BowlingApp/BowlingApp.csproj
+++ b/Sources/BowlingApp/BowlingApp.csproj
@@ -3,6 +3,7 @@
Exe
net6.0
+ $(MSBuildProjectDirectory)
diff --git a/Sources/BowlingApp/Match.cs b/Sources/BowlingApp/Match.cs
index 66470be..fb074e9 100644
--- a/Sources/BowlingApp/Match.cs
+++ b/Sources/BowlingApp/Match.cs
@@ -63,7 +63,13 @@ namespace BowlingApp
///
public static void JeuIndividuel(Saissiseur saissiseur)
{
-
+ // Création des parties pour chaque joueur
+ Manager manager = new Manager(new EquipeDbDataManager(), new PartieDbDataManager(), new JoueurDbDataManager());
+ List j2 = (List)manager.GetAllJoueur().Result;
+ j2.ForEach(joueur =>
+ {
+ Console.WriteLine(joueur.Pseudo);
+ });
Afficheur.InviteNrb("Joueur");
int nbrj = saissiseur.CollecteNbr();
List joueurs = new List();
@@ -78,8 +84,7 @@ namespace BowlingApp
}
- // Création des parties pour chaque joueur
- Manager manager = new Manager(new EquipeDbDataManager(), new PartieDbDataManager(), new JoueurDbDataManager());
+
for (int i = 0; i < joueurs.Count; i++)
{
@@ -119,16 +124,17 @@ namespace BowlingApp
Joueur joueur = new Joueur(Nom);
Partie partie = new Partie(joueur);
Manager manager = new Manager(new EquipeDbDataManager(), new PartieDbDataManager(), new JoueurDbDataManager());
- manager.AddJoueur(joueur);
Lancer(partie, saissiseur);
- manager.AddPartie(partie);
+ joueur.AddPartie(partie);
+ //manager.AddPartie(partie);
+ manager.AddJoueur(joueur);
}
///
/// Faire des lancers
///
///
- ///
+ /// PartieEntities { get; set; } = new List();
#endregion
}
}
\ No newline at end of file
diff --git a/Sources/BowlingEF/Entities/PartieEntity.cs b/Sources/BowlingEF/Entities/PartieEntity.cs
index 54b799b..4929b51 100644
--- a/Sources/BowlingEF/Entities/PartieEntity.cs
+++ b/Sources/BowlingEF/Entities/PartieEntity.cs
@@ -17,11 +17,9 @@ namespace BowlingEF.Entities
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }
- public JoueurEntity Joueur { get; set; }
- [ForeignKey("JoueurId")]
- [Required]
- public long JoueurId { get; set; }
+ [ForeignKey("JoueurForeignKey")]
+ public JoueurEntity Joueur { get; set; }
[Required]
public DateTime Date { get; set; }
public ICollection Frames { get; set; }
diff --git a/Sources/BowlingLib/Model/Frame.cs b/Sources/BowlingLib/Model/Frame.cs
index 2e3f41c..5b5696c 100644
--- a/Sources/BowlingLib/Model/Frame.cs
+++ b/Sources/BowlingLib/Model/Frame.cs
@@ -149,7 +149,7 @@ namespace BowlingLib.Model
///
///
///
- public Frame(long id, int numero, int lancer1, int lancer2, [AllowNull] int lancer3) : this(numero)
+ public Frame(long id, int numero, int lancer1, int lancer2, int lancer3) : this(numero)
{
this.id = id;
Lancer1 = new Lancer(lancer1);
diff --git a/Sources/BowlingLib/Model/Joueur.cs b/Sources/BowlingLib/Model/Joueur.cs
index 21059d9..af1132c 100644
--- a/Sources/BowlingLib/Model/Joueur.cs
+++ b/Sources/BowlingLib/Model/Joueur.cs
@@ -4,6 +4,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Collections.ObjectModel;
+
namespace BowlingLib.Model
{
///
@@ -14,12 +16,16 @@ namespace BowlingLib.Model
#region Propriétés
private string pseudo;
private readonly long id;
+
+ private readonly List parties=new();
+ public ReadOnlyCollection Parties { get; }
#endregion
#region Constructeurs
public Joueur(string pseudo)
{
this.Pseudo = pseudo;
+ Parties = new ReadOnlyCollection(parties);
}
public Joueur(long id, string pseudo) : this(pseudo)
@@ -76,6 +82,11 @@ namespace BowlingLib.Model
return Pseudo.GetHashCode();
}
+ public void AddPartie(Partie p)
+ {
+ parties.Add(p);
+ }
+
#endregion
}
}
diff --git a/Sources/BowlingLib/Model/Partie.cs b/Sources/BowlingLib/Model/Partie.cs
index 88f4fdc..5216a21 100644
--- a/Sources/BowlingLib/Model/Partie.cs
+++ b/Sources/BowlingLib/Model/Partie.cs
@@ -46,7 +46,7 @@ namespace BowlingLib.Model
public Partie(Joueur joueur)
{
this.Joueur = joueur;
-
+ Date = DateTime.Now;
Frames = new ReadOnlyCollection(frames);
}
@@ -77,6 +77,7 @@ namespace BowlingLib.Model
/// le Score d'une partie
public int? GetScore()
{
+ score = 0;
for (int i = 0; i < Frames.Count; i++)
{
score += Frames[i].QuillesTombees;
diff --git a/Sources/BowlingMaping/JoueurDbDataManager.cs b/Sources/BowlingMaping/JoueurDbDataManager.cs
index 75ddc72..1f467ac 100644
--- a/Sources/BowlingMaping/JoueurDbDataManager.cs
+++ b/Sources/BowlingMaping/JoueurDbDataManager.cs
@@ -3,8 +3,10 @@ using BowlingEF.Entities;
using BowlingLib.Model;
using Business;
using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -27,13 +29,51 @@ namespace BowlingMaping
bool result = false;
using (var context = new BowlingContext())
{
- JoueurEntity entity=new JoueurEntity
+ try
{
- Id = _joueur.Id,
- Pseudo = _joueur.Pseudo,
- };
- context.Joueurs.Add(entity);
- result =await context.SaveChangesAsync() == 1;
+ //Mapping entre la classe joueur et la classe joueurEntity
+ JoueurEntity entity = new JoueurEntity
+ {
+ Id = _joueur.Id,
+ Pseudo = _joueur.Pseudo,
+ };
+
+ //Parcourt de la liste des parties d'un joueur
+ for (int i = 0; i < _joueur.Parties.Count; i++)
+ {
+ //Mapping entre les parties d'un joueur et les partieEntity d'une partieEntity
+ PartieEntity partieEntity = new PartieEntity
+ {
+ Joueur = entity,
+ Date = _joueur.Parties[i].Date,
+ Score = _joueur.Parties[i].Score
+
+ };
+
+ //Parcourt de la liste des frames d'une partie
+ for (int j = 0; j < _joueur.Parties[i].Frames.Count; j++)
+ {
+ //Mapping entre les frames d'une partie et les frameEntity d'une partieEntity
+ FrameEntity frameEntity = new FrameEntity
+ {
+ Id = _joueur.Parties[i].Frames[j].Id,
+ Lancer1 = _joueur.Parties[i].Frames[j].Lancer1.QuillesTombees,
+ Lancer2 = _joueur.Parties[i].Frames[j].Lancer2.QuillesTombees,
+ Lancer3 = (_joueur.Parties[i].Frames[j].Lancer3 == null) ? 0 : _joueur.Parties[i].Frames[j].Lancer3.QuillesTombees,//si Lancer3 est null il prend la valeur Zero
+ Partie = partieEntity
+ };
+ partieEntity.Frames.Add(frameEntity);
+ }
+ entity.PartieEntities.Add(partieEntity);
+ }
+ context.Joueurs.Add(entity);
+ result = await context.SaveChangesAsync() == 1;
+ }
+ catch (Exception ex)
+ {
+ Debug.WriteLine(ex);
+ throw;
+ }
}
return result;
}
diff --git a/Sources/BowlingMaping/PartieDbDataManager.cs b/Sources/BowlingMaping/PartieDbDataManager.cs
index 4934ccc..deab746 100644
--- a/Sources/BowlingMaping/PartieDbDataManager.cs
+++ b/Sources/BowlingMaping/PartieDbDataManager.cs
@@ -31,12 +31,21 @@ namespace BowlingMaping
{
Id = _partie.Id,
Date = _partie.Date,
- JoueurId = _partie.Joueur.Id,
Score = _partie.Score
};
context.Parties.Add(entity);
- result = await context.SaveChangesAsync() == 1;
+ try
+ {
+ var data = await context.SaveChangesAsync();
+ result = data == 1;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex);
+ throw;
+ }
}
+
return result;
}
@@ -69,7 +78,7 @@ namespace BowlingMaping
{
PartieEntity entity = context.Parties.Find(_partie.Id);
entity.Date = _partie.Date;
- entity.JoueurId = _partie.Joueur.Id;
+ //entity.JoueurId = _partie.Joueur.Id;
entity.Score = _partie.Score;
result =await context.SaveChangesAsync() == 1;
}