예제 #1
0
        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));
        }
예제 #2
0
 public static D_Score UnMapScore(L_Score score)
 {
     return(new D_Score
     {
         ScoreId = score.ScoreId,
         UserId = score.UserId,
         GameId = score.GameId,
         Score = score.Score
     });
 }
예제 #3
0
        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());
        }
예제 #4
0
        /// <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();
        }
예제 #5
0
 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);
 }
예제 #6
0
        /// <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();
        }
예제 #7
0
        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));
        }
예제 #8
0
 public IActionResult Post(L_Score score)
 {
     _scoreRepository.AddScore(score);
     return(CreatedAtAction(nameof(GetById), new { id = score.ScoreId }, score));
 }