public DTO.Player JoinLobby(DTO.Lobby lobby, DTO.Player player) { //Om speler te laten joinen in een lobby DTO.Player returnplay = new DTO.Player(); try { // als een speler een host is van een lobby --> stop lobby if (player.IsHost == true) { StopHost(player); } var join = (from l in db.Players where l.PlayerId == player.PlayerId select l).First(); var isthere = (from l in db.Lobbis where l.HostID == lobby.HostID select l); if (isthere != null) { join.Lobby = lobby.HostPlayer; join.HostID = lobby.HostID; join.Locatie = 0; join.Diced = 0; join.Rule_19 = false; join.Rule_32 = false; join.Rule_52 = false; db.SubmitChanges(); updatelobby(lobby.HostID); } returnplay = player; returnplay.HostID = lobby.HostID; returnplay.Lobby = lobby.HostPlayer; return returnplay; } catch (Exception) { return returnplay; } }
public DTO.Player Inloggen(string naam, string wachtwoord) { try { DTO.Player player = new DTO.Player(); var user = (from u in db.Players where u.PlayerNaam == naam && u.Wachtwoord == wachtwoord select u).First(); if (user != null) { player.PlayerId = user.PlayerId; player.PlayerNaam = user.PlayerNaam; player.Lobby = user.Lobby; if (user.HostID.HasValue) { player.HostID = user.HostID.Value; } player.Locatie = user.Locatie; StopHost(player); if (user.Gewonnen.HasValue) { player.Gewonnen = user.Gewonnen.Value; } if (user.Verloren.HasValue) { player.Verloren = user.Verloren.Value; } user.Locatie = 0; user.Rule_19 = false; user.Rule_52 = false; user.IsHost = false; db.SubmitChanges(); player.IsHost = false; return player; } else return null; } catch (Exception) { return null; } }