Пример #1
0
        public async Task UpsertPlayerScoringAsync(string playerId, decimal points, IEnumerable <int> milestoneIndices)
        {
            try
            {
                // get scoring
                ScoringDto scoringDto = await _context.Scorings.FindAsync(playerId);

                if (scoringDto != null)
                {
                    scoringDto.Score = points;
                    if (milestoneIndices != null && milestoneIndices.Any())
                    {
                        scoringDto.CompletedMilestoneIndices = string.Join(",", milestoneIndices.Select(m => m.ToString()));
                    }
                }
                else
                {
                    await _context.Scorings.AddAsync(new ScoringDto { PlayerId = playerId, Score = points, });
                }

                await _context.SaveChangesAsync();
            }
            catch
            {
            }
        }
Пример #2
0
        public async Task <PlayerScoring> GetPlayerScoringAsync(string playerId)
        {
            ScoringDto scoringDto = await _context.Scorings.FindAsync(playerId);

            PlayerScoring scoring;

            if (scoringDto != null)
            {
                scoring = new PlayerScoring
                {
                    PlayerId = scoringDto.PlayerId,
                    Score    = scoringDto.Score,
                    CompletedMilestoneIndices =
                        scoringDto.CompletedMilestoneIndices?.Split(',').Select(m => int.Parse(m))
                        ?? Enumerable.Empty <int>()
                }
            }
            ;
            else
            {
                scoring = new PlayerScoring {
                    PlayerId = playerId
                };
            }

            return(scoring);
        }