public void MapScoreTest() { D_Score sampleScoreD = new D_Score { ScoreId = 100, UserId = 100, GameId = 100, Score = 5566, User = new D_User { Username = "******" }, Game = new D_Game { GameName = "Test Game Name." } }; L_Score sampleScoreL = new L_Score { ScoreId = 100, UserId = 100, Username = "******", GameId = 100, GameName = "Test Game Name.", Score = 5566 }; L_Score resultScoreL = Mapper.MapScore(sampleScoreD); Assert.True(compareScoreL(resultScoreL, sampleScoreL)); }
public static D_Score UnMapScore(L_Score score) { return(new D_Score { ScoreId = score.ScoreId, UserId = score.UserId, GameId = score.GameId, Score = score.Score }); }
public async Task <IActionResult> Put(int id, [FromBody] L_Score score) { // successful update for PUT returns 204 No Content with empty body, or 200 OK if (await _scoreRepository.GetScoreById(id) is L_Score oldScore) { await _scoreRepository.UpdateScore(score); return(NoContent()); //return StatusCode(204); } return(NotFound()); }
/// <summary> Changes all score related to a particular existing score. /// <param name="inputScore"> object L_Score (name of object) - This is a logic object of type Score. </param> /// <returns> void </returns> /// </summary> public async Task UpdateScore(L_Score inputScore) { _logger.LogInformation($"Updating score with ID {inputScore.ScoreId}"); D_Score currentEntity = await _dbContext.Scores .Include(p => p.User) .Include(p => p.Game) .FirstOrDefaultAsync(p => p.ScoreId == inputScore.ScoreId); D_Score newEntity = Mapper.UnMapScore(inputScore); _dbContext.Entry(currentEntity).CurrentValues.SetValues(newEntity); Save(); }
private bool compareScoreL(L_Score x, L_Score y) { if ( x.GameId != y.GameId || x.GameName != y.GameName || x.Score != y.Score || x.ScoreId != y.ScoreId || x.UserId != y.ScoreId || x.Username != y.Username ) { return(false); } return(true); }
/// <summary> Adds a new game data to the database. /// <param name="inputScore"> object L_Score (name of object) - This is a logic object of type score. </param> /// <returns> void </returns> /// </summary> public void AddScore(L_Score inputScore) { if (inputScore.ScoreId != 0) { _logger.LogWarning($"Score to be added has an ID ({inputScore.ScoreId}) already!"); throw new ArgumentException("Id already exists when trying to add a new score!", $"{inputScore.ScoreId}"); } _logger.LogInformation("Adding game."); D_Score entity = Mapper.UnMapScore(inputScore); entity.ScoreId = 0; _dbContext.Add(entity); Save(); }
public void UnMapScoreTest() { L_Score sampleScoreL = new L_Score { ScoreId = 100, UserId = 100, GameId = 100, Score = 5566, Username = "******", GameName = "Test Game Name." }; D_Score sampleScoreD = new D_Score { ScoreId = 100, UserId = 100, GameId = 100, Score = 5566 }; D_Score resultScoreD = Mapper.UnMapScore(sampleScoreL); Assert.True(compareScoreD(resultScoreD, sampleScoreD)); }
public IActionResult Post(L_Score score) { _scoreRepository.AddScore(score); return(CreatedAtAction(nameof(GetById), new { id = score.ScoreId }, score)); }