// RpsDBContext myDBContext = new RpsDBContext(); public RGB_GameRepositoryLayer() { using (RpsDBContext Db = new RpsDBContext()) { lstMatchesHistory = Db.matches.ToList(); Players = Db.players.ToList(); } }
public Round BeginRoundGame(Player UserPlayer, string strUserResponse, Player ComputerPlayer) { Round round = new Round(); round.PlayerChoice = this.AsignGameOptionsToPlayer(UserPlayer, strUserResponse); round.Player2Choice = this.AsignGameOptionsToPlayer(ComputerPlayer); this.Rounds.Add(round); using (RpsDBContext Db = new RpsDBContext()) { Db.rounds.Add(round); Db.SaveChanges(); } return(round); }
/// <summary> /// It will verify if the player exists in the List of Players and will add it if do not exists. /// </summary> /// <param name="player">The object Player that we want to verify if it ex</param> /// <returns></returns> public Player CreatePlayer(string firstName = "null", string lastName = "null") { if (!this.Players.Exists(lexpr => lexpr.FirstName == firstName && lexpr.LastName == lastName)) //!this.Players.Exists( lexpr => lexpr.FirstName == firstName && lexpr.LastName == lastName ) { Player player = new Player() { FirstName = firstName, LastName = lastName }; this.Players.Add(player); using (RpsDBContext Db = new RpsDBContext()) { Db.players.Add(player); Db.SaveChanges(); } return(player); } return(this.Players.Find(lexpr => lexpr.FirstName == firstName && lexpr.LastName == lastName)); }