Example #1
0
        public void MapGameTest()
        {
            D_Game sampleGameD = new D_Game
            {
                GameId          = 100,
                GameName        = "Test Game Name.",
                GameDescription = "Test Game Description",
                Reviews         = new List <D_Review> {
                },
                Scores          = new List <D_Score> {
                },
                Data            = new List <D_GameData> {
                }
            };

            L_Game sampleGameL = new L_Game
            {
                GameId          = 100,
                GameName        = "Test Game Name.",
                GameDescription = "Test Game Description",
                Reviews         = new List <L_Review> {
                },
                Scores          = new List <L_Score> {
                },
                Data            = new List <L_GameData> {
                }
            };

            L_Game resultGameL = Mapper.MapGame(sampleGameD);

            Assert.True(compareGameL(resultGameL, sampleGameL));
        }
Example #2
0
 public static D_Game UnMapGame(L_Game game)
 {
     return(new D_Game
     {
         GameId = game.GameId,
         GameName = game.GameName,
         GameDescription = game.GameDescription
     });
 }
        public async Task <IActionResult> Put(int id, [FromBody] L_Game Game)
        {
            // successful update for PUT returns 204 No Content with empty body, or 200 OK
            if (await _GameRepository.GetGameById(id) is L_Game oldGame)
            {
                await _GameRepository.UpdateGame(Game);

                return(NoContent());
                //return StatusCode(204);
            }
            return(NotFound());
        }
Example #4
0
        /// <summary> Changes all game related to a particular existing game.
        /// <param name="inputGame"> object L_Game (name of object) - This is a logic object of type game. </param>
        /// <returns> void </returns>
        /// </summary>
        public async Task UpdateGame(L_Game inputGame)
        {
            _logger.LogInformation($"Updating game with ID {inputGame.GameId}");
            D_Game currentEntity = await _dbContext.Games
                                   .Include(p => p.Scores)
                                   .Include(p => p.Reviews)
                                   .Include(p => p.Data)
                                   .FirstOrDefaultAsync(p => p.GameId == inputGame.GameId);

            D_Game newEntity = Mapper.UnMapGame(inputGame);

            _dbContext.Entry(currentEntity).CurrentValues.SetValues(newEntity);
            Save();
        }
Example #5
0
 private bool compareGameL(L_Game x, L_Game y)
 {
     if (
         x.GameId != y.GameId ||
         x.GameDescription != y.GameDescription ||
         x.GameName != y.GameName ||
         x.Data.Count != y.Data.Count ||
         x.Reviews.Count != y.Reviews.Count ||
         x.Scores.Count != y.Scores.Count
         )
     {
         return(false);
     }
     return(true);
 }
Example #6
0
        /// <summary> Adds a new game to the database.
        /// <param name="inputGame"> object L_Game (name of object) - This is a logic object of type game. </param>
        /// <returns> void </returns>
        /// </summary>
        public void AddGame(L_Game inputGame)
        {
            if (inputGame.GameId != 0)
            {
                _logger.LogWarning($"Game to be added has an ID ({inputGame.GameId}) already!");
                throw new ArgumentException("Id already exists when trying to add a new game!", $"{inputGame.GameId}");
            }

            _logger.LogInformation("Adding game.");

            D_Game entity = Mapper.UnMapGame(inputGame);

            entity.GameId = 0;
            _dbContext.Add(entity);
            Save();
        }
Example #7
0
        public void UnMapGameTest()
        {
            L_Game sampleGameL = new L_Game
            {
                GameId          = 100,
                GameName        = "Test Game Name.",
                GameDescription = "Test Game Description",
            };

            D_Game sampleGameD = new D_Game
            {
                GameId          = 100,
                GameName        = "Test Game Name.",
                GameDescription = "Test Game Description",
            };

            D_Game resultGameD = Mapper.UnMapGame(sampleGameL);

            Assert.True(compareGameD(resultGameD, sampleGameD));
        }
 public IActionResult Post(L_Game Game)
 {
     _GameRepository.AddGame(Game);
     return(CreatedAtAction(nameof(GetById), new { id = Game.GameId }, Game));
 }