Пример #1
0
 /// <summary>
 /// Returns all games associated with player id
 /// </summary>
 /// <param name="playerId"></param>
 /// <returns></returns>
 public static IEnumerable<Game> GetGamesByPlayerId(int playerId)
 {
     IPingPongRepository<Game> _repo = new PingPongRepository<Game>();
     var games = _repo.FindBy(x => x.ChallengerId == playerId || x.DefenderId == playerId)
                 .ToList();
     return games;
 }
 // GET: Games/Details/5
 public ActionResult Details(int id)
 {
     if (String.IsNullOrEmpty(User.Identity.Name))
     {
         return RedirectToAction("Login", "Account");
     }
     var repo = new PingPongRepository<Game>();
     var game = repo.FindBy(x => x.GameId == id).SingleOrDefault();
     return View(game);
 }
Пример #3
0
 /// <summary>
 /// Creates a new game
 /// </summary>
 public static void CreateNewGame(Game game)
 {
     IPingPongRepository<Game> _repo = new PingPongRepository<Game>();
     _repo.Create(game);
 }
Пример #4
0
 /// <summary>
 /// Updates an existing game
 /// </summary>
 public static void UpdateExistingGame(Game game)
 {
     IPingPongRepository<Game> _repo = new PingPongRepository<Game>();
     _repo.Update(game);
 }
Пример #5
0
 /// <summary>
 /// Gets second latest gamne
 /// </summary>
 /// <param name="userId"></param>
 /// <returns></returns>
 public static Game GetSecondToLastGame(int userId)
 {
     IPingPongRepository<Game> _repo = new PingPongRepository<Game>();
     //This needs to be refactored. Looks terrible
     var games = _repo.FindBy(x => x.ChallengerId == userId || x.DefenderId == userId).ToList();
     var latestGame = games.OrderByDescending(x => x.GameId).First();
     games.Remove(latestGame);
     return games.OrderByDescending(x => x.GameId).FirstOrDefault();
 }
Пример #6
0
 public static int GetNumberOfGamesForPlayer(int id)
 {
     IPingPongRepository<Game> _repo = new PingPongRepository<Game>();
     var gameCount = _repo.FindBy(x => x.ChallengerId == id || x.DefenderId == id).Count();
     return gameCount;
 }
 /// <summary>
 /// Returns player's full name based on identification number
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public static string GetPlayerFullNameById(int id)
 {
     IPingPongRepository<Player> _repo = new PingPongRepository<Player>();
     var fullname = _repo.FindBy(x => x.PlayerId == id)
                     .Select(x => x.FirstName + " " + x.LastName)
                     .SingleOrDefault();
     return fullname;
 }
Пример #8
0
 /// <summary>
 /// Finds latest game by user id
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public static Game FindLatestGameByUserId(int id)
 {
     try
     {
         IPingPongRepository<Game> _repo = new PingPongRepository<Game>();
         var games = _repo.FindBy(x => x.ChallengerId == id || x.DefenderId == id).ToList();
         var latestGameId = games.Max(x => x.GameId);
         return _repo.FindBy(x => x.GameId == latestGameId).SingleOrDefault();
     }
     catch (Exception)
     {
         throw new Exception("You have no existing games");
     }
     
 }
 /// <summary>
 /// Returns all player objects
 /// </summary>
 /// <returns></returns>
 private static IEnumerable<Player> GetAllPlayers()
 {
     IPingPongRepository<Player> _repo = new PingPongRepository<Player>();
     var players = _repo.GetAll();
     return players;
 }
 /// <summary>
 /// Deletes an existing Player
 /// </summary>
 public static void DeleteExistingPlayer(Player player)
 {
     IPingPongRepository<Player> _repo = new PingPongRepository<Player>();
     _repo.Delete(player.PlayerId);
 }
 /// <summary>
 /// Updates an existing Player
 /// </summary>
 public static void UpdateExistingPlayer(Player player)
 {
     IPingPongRepository<Player> _repo = new PingPongRepository<Player>();
     _repo.Update(player);
 }
 /// <summary>
 /// Creates a new Player
 /// </summary>
 public static void CreateNewPlayer(Player player)
 {
     IPingPongRepository<Player> _repo = new PingPongRepository<Player>();
     _repo.Create(player);
 }
 /// <summary>
 /// Returns boolean value based on whether password is correct
 /// </summary>
 /// <param name="id"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public static bool IsCorrectPassword(int id, string password)
 {
     IPingPongRepository<Player> _repo = new PingPongRepository<Player>();
     var pw = _repo.FindBy(x => x.PlayerId == id).Select(x => x.Password).SingleOrDefault();
     return password == pw;
 }
 /// <summary>
 /// Retrieves player by indentification number
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public static Player GetPlayerById(int id)
 {
     IPingPongRepository<Player> _repo = new PingPongRepository<Player>();
     var player = _repo.FindBy(x => x.PlayerId == id)
                 .SingleOrDefault();
     return player;
 }
Пример #15
0
 /// <summary>
 /// Deletes an existing game
 /// </summary>
 public static void DeleteExistingGame(Game game)
 {
     IPingPongRepository<Game> _repo = new PingPongRepository<Game>();
     _repo.Delete(game.GameId);
 }
Пример #16
0
 /// <summary>
 /// Deletes existing game by identification number
 /// </summary>
 /// <param name="id"></param>
 public static void DeleteExistingGameById(int id)
 {
     IPingPongRepository<Game> _repo = new PingPongRepository<Game>();
     _repo.Delete(id);
 }
 /// <summary>
 /// Returns player based on password
 /// </summary>
 /// <param name="password">Player's password</param>
 /// <returns></returns>
 public static Player GetPlayerByPassword(string password)
 {
     IPingPongRepository<Player> _repo = new PingPongRepository<Player>();
     var player = _repo.FindBy(x => x.Password == password)
                  .SingleOrDefault();
     return player;
 }
Пример #18
0
 /// <summary>
 /// Returns game by identification number
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public static Game GetGameById(int id)
 {
     IPingPongRepository<Game> _repo = new PingPongRepository<Game>();
     var game = _repo.FindBy(x => x.GameId == id).SingleOrDefault();
     return game;
 }
 /// <summary>
 /// Returns Players full name based on username
 /// </summary>
 /// <param name="username"></param>
 /// <returns></returns>
 public static string GetPlayerFullNameByUsername(string username)
 {
     IPingPongRepository<Player> _repo = new PingPongRepository<Player>();
     var fullname = _repo.FindBy(x => x.LoginName == username)
                    .Select(x => x.FirstName + " " + x.LastName)
                    .SingleOrDefault();
     return fullname;
 }