|
|
|
@ -18,14 +18,14 @@ namespace EntityManagers
|
|
|
|
|
|
|
|
|
|
public async Task<LobbyEntity> addLobby(LobbyEntity lobby)
|
|
|
|
|
{
|
|
|
|
|
var tmp = await dbContext.Lobbies.Where(l => l.Equals(lobby)).FirstOrDefaultAsync();
|
|
|
|
|
var tmp = await dbContext.Lobbies.Where(l => l.IdCreator == lobby.IdCreator && l.Name == lobby.Name).FirstOrDefaultAsync();
|
|
|
|
|
if (tmp != null) // <=> he already exist
|
|
|
|
|
{
|
|
|
|
|
return tmp!;
|
|
|
|
|
}
|
|
|
|
|
dbContext.Lobbies.Add(lobby);
|
|
|
|
|
await dbContext.SaveChangesAsync();
|
|
|
|
|
return await dbContext.Lobbies.Where(l => l.Equals(lobby)).FirstAsync();
|
|
|
|
|
return await dbContext.Lobbies.Where(l => l.IdCreator == lobby.IdCreator && l.Name == lobby.Name).FirstAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<(int nbPages, IEnumerable<LobbyEntity>? lobbies)> getLobbies(int nb, int count, LobbyOrderCriteria orderCriteria = LobbyOrderCriteria.ById)
|
|
|
|
@ -50,7 +50,19 @@ namespace EntityManagers
|
|
|
|
|
|
|
|
|
|
public async Task<LobbyEntity?> getLobby(int id)
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult<LobbyEntity?>(dbContext.Lobbies.Where(l => l.Id == id).FirstOrDefault());
|
|
|
|
|
return await dbContext.Lobbies.SingleOrDefaultAsync(l => l.Id == id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<LobbyEntity?> getLobby(string name, int? idCreator)
|
|
|
|
|
{
|
|
|
|
|
if(name == null)
|
|
|
|
|
{
|
|
|
|
|
var tmp = dbContext.Lobbies.Where(l => l.Name == name && l.IdCreator != null);
|
|
|
|
|
if (tmp.Count() == 0) return null;
|
|
|
|
|
else if (tmp.Count() == 1) return tmp.First();
|
|
|
|
|
else throw new Exception("too much lobbies");
|
|
|
|
|
}
|
|
|
|
|
return await dbContext.Lobbies.SingleOrDefaultAsync(l => l.Name == name && l.IdCreator == idCreator);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNbLobbies()
|
|
|
|
@ -60,7 +72,7 @@ namespace EntityManagers
|
|
|
|
|
|
|
|
|
|
public async Task<LobbyEntity?> removeLobby(LobbyEntity lobby)
|
|
|
|
|
{
|
|
|
|
|
var tmp = dbContext.Lobbies.Where(a => a.Equals(lobby)).FirstOrDefaultAsync().Result;
|
|
|
|
|
var tmp = dbContext.Lobbies.Where(l => l.IdCreator == lobby.IdCreator && l.Name == lobby.Name).FirstOrDefaultAsync().Result;
|
|
|
|
|
if (tmp == null) return await Task.FromResult<LobbyEntity?>(tmp);
|
|
|
|
|
dbContext.Lobbies.Remove(tmp);
|
|
|
|
|
await dbContext.SaveChangesAsync();
|
|
|
|
|