|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
using BowlingEF.Entities;
|
|
|
|
|
using BowlingLib.Model;
|
|
|
|
|
using Business;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
@ -21,7 +22,7 @@ namespace BowlingMaping
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="_joueur"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool Add(Joueur _joueur)
|
|
|
|
|
public async Task<bool> Add(Joueur _joueur)
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
using (var context = new BowlingContext())
|
|
|
|
@ -32,7 +33,7 @@ namespace BowlingMaping
|
|
|
|
|
Pseudo = _joueur.Pseudo,
|
|
|
|
|
};
|
|
|
|
|
context.Joueurs.Add(entity);
|
|
|
|
|
result = context.SaveChanges() == 1;
|
|
|
|
|
result =await context.SaveChangesAsync() == 1;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
@ -42,7 +43,7 @@ namespace BowlingMaping
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="_joueur"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool Delete(Joueur _joueur)
|
|
|
|
|
public async Task< bool> Delete(Joueur _joueur)
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
|
@ -52,7 +53,7 @@ namespace BowlingMaping
|
|
|
|
|
{
|
|
|
|
|
JoueurEntity entity = context.Joueurs.Find(_joueur.Id);
|
|
|
|
|
context.Joueurs.Remove(entity);
|
|
|
|
|
result = context.SaveChanges() == 1;
|
|
|
|
|
result = await context.SaveChangesAsync() == 1;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
@ -64,12 +65,12 @@ namespace BowlingMaping
|
|
|
|
|
/// recupère tous les joueurs de la Base de données
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public IEnumerable<Joueur> GetAll()
|
|
|
|
|
public async Task< IEnumerable<Joueur> >GetAll()
|
|
|
|
|
{
|
|
|
|
|
using (var context = new BowlingContext())
|
|
|
|
|
{
|
|
|
|
|
List<Joueur> joueurs = new List<Joueur>();
|
|
|
|
|
foreach (var item in context.Joueurs)
|
|
|
|
|
List<Joueur> joueurs = new List<Joueur>();
|
|
|
|
|
foreach (var item in await context.Joueurs.ToListAsync())
|
|
|
|
|
joueurs.Add(new Joueur(item.Id, item.Pseudo));
|
|
|
|
|
return joueurs;
|
|
|
|
|
}
|
|
|
|
@ -80,22 +81,19 @@ namespace BowlingMaping
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Joueur GetDataWithName(string name)
|
|
|
|
|
public async Task<Joueur> GetDataWithName(string name)
|
|
|
|
|
{
|
|
|
|
|
using (var context = new BowlingContext())
|
|
|
|
|
{
|
|
|
|
|
Joueur _joueur = null;
|
|
|
|
|
|
|
|
|
|
var query = from joueur in context.Joueurs
|
|
|
|
|
where joueur.Pseudo == name
|
|
|
|
|
select joueur;
|
|
|
|
|
foreach (var item in query)
|
|
|
|
|
_joueur = new Joueur(item.Id, item.Pseudo);
|
|
|
|
|
|
|
|
|
|
var query = await context.Joueurs.FirstOrDefaultAsync(n => n.Pseudo == n.Pseudo);
|
|
|
|
|
_joueur = new Joueur(query.Id, query.Pseudo);
|
|
|
|
|
return _joueur;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Update(Joueur _joueur)
|
|
|
|
|
public async Task<bool> Update(Joueur _joueur)
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
using (var context = new BowlingContext())
|
|
|
|
@ -104,7 +102,7 @@ namespace BowlingMaping
|
|
|
|
|
if (entity!=null)
|
|
|
|
|
{
|
|
|
|
|
entity.Pseudo = _joueur.Pseudo;
|
|
|
|
|
result = context.SaveChanges() == 1;
|
|
|
|
|
result = await context.SaveChangesAsync() == 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|