public void UnMapGameDataTest() { L_GameData sampleGameDataL = new L_GameData { DataId = 100, GameId = 1, GameName = "Memory Bingo", Difficulty = 10, Question = "Test Question.", Answer = "Test Answer." }; D_GameData sampleGameDataD = new D_GameData { DataId = 100, GameId = 1, Difficulty = 10, Question = "Test Question.", Answer = "Test Answer." }; D_GameData resultGameDataD = Mapper.UnMapGameData(sampleGameDataL); Assert.True(compareGameDataD(resultGameDataD, sampleGameDataD)); }
public void MapGameDataTest() { D_GameData sampleGameDataD = new D_GameData { DataId = 100, GameId = 100, Difficulty = 10, Question = "Test Question.", Answer = "Test Answer.", Game = new D_Game { GameName = "Test Game." } }; L_GameData sampleGameDataL = new L_GameData { DataId = 100, GameId = 100, GameName = "Test Game.", Difficulty = 10, Question = "Test Question.", Answer = "Test Answer." }; L_GameData resultGameDataL = Mapper.MapGameData(sampleGameDataD); Assert.True(compareGameDataL(resultGameDataL, sampleGameDataL)); }
public static D_GameData UnMapGameData(L_GameData gameData) { return(new D_GameData { DataId = gameData.DataId, GameId = gameData.GameId, Difficulty = gameData.Difficulty, Question = gameData.Question, Answer = gameData.Answer }); }
/// <summary> Changes all game data related to a particular existing game data. /// <param name="inputGameData"> object L_GameData (name of object) - This is a logic object of type game data. </param> /// <returns> void </returns> /// </summary> public async Task UpdateGameData(L_GameData inputGameData) { _logger.LogInformation($"Updating game data with ID {inputGameData.DataId}"); D_GameData currentEntity = await _dbContext.GameDatas .Include(p => p.Game) .FirstOrDefaultAsync(p => p.DataId == inputGameData.DataId); D_GameData newEntity = Mapper.UnMapGameData(inputGameData); _dbContext.Entry(currentEntity).CurrentValues.SetValues(newEntity); Save(); }
public async Task <IActionResult> Put(int id, [FromBody] L_GameData gameData) { // successful update for PUT returns 204 No Content with empty body, or 200 OK if (await _gameDataRepository.GetGameDataById(id) is L_GameData oldGameData) { await _gameDataRepository.UpdateGameData(gameData); return(NoContent()); //return StatusCode(204); } return(NotFound()); }
private bool compareGameDataL(L_GameData x, L_GameData y) { if ( x.Answer != y.Answer || x.DataId != y.DataId || x.Difficulty != y.Difficulty || x.GameId != y.GameId || x.GameName != y.GameName || x.Question != y.Question ) { return(false); } return(true); }
/// <summary> Adds a new game data to the database. /// <param name="inputGameData"> object L_GameData (name of object) - This is a logic object of type game data. </param> /// <returns> void </returns> /// </summary> public void AddGameData(L_GameData inputGameData) { if (inputGameData.DataId != 0) { _logger.LogWarning($"Game data to be added has an ID ({inputGameData.DataId}) already!"); throw new ArgumentException("Id already exists when trying to add a new game data!", $"{inputGameData.DataId}"); } _logger.LogInformation("Adding game data."); D_GameData entity = Mapper.UnMapGameData(inputGameData); entity.DataId = 0; _dbContext.Add(entity); Save(); }
public IActionResult Post(L_GameData gameData) { _gameDataRepository.AddGameData(gameData); return(CreatedAtAction(nameof(GetById), new { id = gameData.DataId }, gameData)); }