public async Task <IActionResult> AddScore([FromBody] ScoreModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Bad Username!"));
            }
            //Check for new or update
            var old = await _db.Scores.FirstOrDefaultAsync <ScoreModel>(o => o.UserName == model.UserName);

            if (old == null)
            {
                //New
                _db.Scores.Add(model);
                await _db.SaveChangesAsync();

                return(Ok(model));
            }
            else
            {
                //UPDATE
                old.Points = model.Points;
                await _db.SaveChangesAsync();

                return(Ok(model));
            }
        }
 /// <summary>
 /// Adds a new entry to the leaderboards.
 /// </summary>
 /// <param name="entry">New entry to be added.</param>
 /// <returns>Void result of task execution.</returns>
 public override async Task AddLeaderboardEntryAsync(LeaderboardEntry entry)
 {
     using (var context = new ScoreDbContext())
     {
         context.Leaderboards.Add(entry);
         await context.SaveChangesAsync();
     }
 }
Example #3
0
        public string GetFakeTokkenAsync(String username)
        {
            var old = _db.Scores.FirstOrDefaultAsync <ScoreModel>(o => o.UserName == username);

            if (old == null)
            {
                _db.Scores.Add(new ScoreModel()
                {
                    UserName = username, Points = 0
                });
                _db.SaveChangesAsync();
            }
            return(generateJwtToken(username));
        }