private GamesResult GetGamesResult(int leagueID) { var dataCache = new DataCache(); var teams = TeamsService.GetInstance().GetTeams(leagueID: leagueID, showAll: true, dataCache: dataCache); var games = GamesService.GetInstance().GetGames(leagueID: leagueID, dataCache: dataCache); var gamesResult = new GamesResult() { Teams = teams.Select(t => new TeamsResult() { ID = t.ID, Name = t.Name }).ToList(), Games = games.Select(g => new GameResultBase() { ID = g.ID, GameDate = g.GameDate, Team1ID = g.Team1ID, Team1Name = teams.FirstOrDefault(tm1 => tm1.ID == g.Team1ID)?.Name, Team1Score = g.Team1Score, Team2ID = g.Team2ID, Team2Name = teams.FirstOrDefault(tm2 => tm2.ID == g.Team2ID)?.Name, Team2Score = g.Team2Score }).ToList() }; return(gamesResult); }
public static GamesResult GetGamesResult(string username) { IHangmanRepository repository = HangmanRepositoryFactory.CreateRepository(); int playerID = repository.GetPlayerID(username); GamesResult result = repository.GetGamesResultForPlayer(playerID); return(result); }
// POST api/GamesResults public HttpResponseMessage Post([FromBody] GamesResult gameRes) { using (WebAPI_FP_TournamentGamesEntities entities = new WebAPI_FP_TournamentGamesEntities()) { entities.GamesResults.Add(gameRes); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Created, new Uri(Request.RequestUri + gameRes.ID.ToString()))); } }
// // GET: /GamesResult/ public ActionResult Report() { if (System.Web.HttpContext.Current.User == null || !System.Web.HttpContext.Current.User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } GamesResult gamesResult = Game.GetGamesResult(System.Web.HttpContext.Current.User.Identity.Name); return(View(gamesResult)); }
// GET api/GamesResults/5 public HttpResponseMessage Get(int id) { using (WebAPI_FP_TournamentGamesEntities entities = new WebAPI_FP_TournamentGamesEntities()) { GamesResult game = entities.GamesResults.FirstOrDefault(t => t.ID == id); if (game != null) { return(Request.CreateResponse(HttpStatusCode.OK, game)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format("Game with id : {0} , NOT FOUND!!!", id))); } } }
// DELETE api/GamesResults/5 public HttpResponseMessage Delete(int id) { using (WebAPI_FP_TournamentGamesEntities entities = new WebAPI_FP_TournamentGamesEntities()) { GamesResult game = entities.GamesResults.FirstOrDefault(t => t.ID == id); if (game != null) { entities.GamesResults.Remove(game); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Accepted, string.Format("Game with id: {0} , was deleted.", id))); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format("Game with id : {0} , NOT FOUND!!!", id))); } } }
// PUT api/GamesResults/5 public HttpResponseMessage Put(int id, [FromBody] GamesResult game) { using (WebAPI_FP_TournamentGamesEntities entities = new WebAPI_FP_TournamentGamesEntities()) { GamesResult gameUpdate = entities.GamesResults.FirstOrDefault(t => t.ID == id); if (gameUpdate != null) { gameUpdate.Game_Name = game.Game_Name; gameUpdate.Player1 = game.Player1; gameUpdate.Player2 = game.Player2; gameUpdate.Who_Won_ = game.Who_Won_; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Accepted, gameUpdate)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format("Game with id : {0} , NOT FOUND!!!", id))); } } }
public void TestRecordGame() { IHangmanRepository repository = HangmanRepositoryFactory.CreateRepository(); int playerID = repository.GetPlayerID("player1"); if (playerID == 0) { //Add player repository.AddPlayer("player1", "password"); playerID = repository.GetPlayerID("player1"); } int wordID = repository.GetWords(1)[0]; repository.RecordGame(playerID, wordID, 3, 3, true); GamesResult gamesResult = repository.GetGamesResultForPlayer(playerID); Assert.IsTrue(gamesResult.NumberOfGames > 0); Assert.IsTrue(gamesResult.NumberOfSuccess > 0); }
public async Task <IGamesResult> GetMyGames( IGamesRequest request, bool fullRecord = true) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var result = new GamesResult(); try { if (await appsRepository.HasEntity(request.AppId)) { var response = await gamesRepository.GetMyGames( request.UserId, request.AppId, fullRecord); if (response.Success) { if (request.Paginator != null) { if (StaticDataHelpers.IsPageValid(request.Paginator, response.Objects)) { if (request.Paginator.SortBy == SortValue.NULL) { result.Games = response.Objects.ConvertAll(g => (IGame)g); } else if (request.Paginator.SortBy == SortValue.ID) { if (!request.Paginator.OrderByDescending) { foreach (var obj in response.Objects) { result.Games.Add((IGame)obj); } result.Games = result.Games .OrderBy(g => g.Id) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } else { foreach (var obj in response.Objects) { result.Games.Add((IGame)obj); } result.Games = result.Games .OrderByDescending(g => g.Id) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } } else if (request.Paginator.SortBy == SortValue.SCORE) { if (!request.Paginator.OrderByDescending) { foreach (var obj in response.Objects) { result.Games.Add((IGame)obj); } result.Games = result.Games .Where(g => g.Score != 0 && g.Score != int.MaxValue && g.Score != 0 && !g.ContinueGame) .OrderByDescending(g => g.Score) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } else { foreach (var obj in response.Objects) { result.Games.Add((IGame)obj); } result.Games = result.Games .Where(g => g.Score != 0 && g.Score != int.MaxValue && g.Score != 0 && !g.ContinueGame) .OrderBy(g => g.Score) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } } else if (request.Paginator.SortBy == SortValue.DATECREATED) { if (!request.Paginator.OrderByDescending) { foreach (var obj in response.Objects) { result.Games.Add((IGame)obj); } result.Games = result.Games .OrderBy(g => g.DateCreated) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } else { foreach (var obj in response.Objects) { result.Games.Add((IGame)obj); } result.Games = result.Games .OrderByDescending(g => g.DateCreated) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } } else if (request.Paginator.SortBy == SortValue.DATEUPDATED) { if (!request.Paginator.OrderByDescending) { foreach (var obj in response.Objects) { result.Games.Add((IGame)obj); } result.Games = result.Games .OrderBy(g => g.DateUpdated) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } else { foreach (var obj in response.Objects) { result.Games.Add((IGame)obj); } result.Games = result.Games .OrderByDescending(g => g.DateUpdated) .Skip((request.Paginator.Page - 1) * request.Paginator.ItemsPerPage) .Take(request.Paginator.ItemsPerPage) .ToList(); } } else { result.Success = false; result.Message = ServicesMesages.SortValueNotImplementedMessage; return(result); } } else { result.Success = false; result.Message = ServicesMesages.PageNotFoundMessage; return(result); } } else { result.Games = response.Objects.ConvertAll(g => (IGame)g); } if (fullRecord) { foreach (var game in result.Games) { foreach (var userRole in game.User.Roles) { userRole.Role.Users = null; } game.User.Apps = null; game.SudokuMatrix.Difficulty.Matrices = null; } } else { foreach (var game in result.Games) { game.User = null; game.SudokuMatrix = null; game.SudokuSolution = null; } } result.Success = response.Success; result.Message = GamesMessages.GamesFoundMessage; return(result); } else if (!response.Success && response.Exception != null) { result.Success = response.Success; result.Message = response.Exception.Message; return(result); } else { result.Success = false; result.Message = GamesMessages.GamesNotFoundMessage; return(result); } } else { result.Success = false; result.Message = AppsMessages.AppNotFoundMessage; return(result); } } catch (Exception exp) { result.Success = false; result.Message = exp.Message; return(result); } }