コード例 #1
0
 public async Task PostAsync([FromBody] Score submitScore)
 {
     if (!TryValidateModel(submitScore, nameof(submitScore)))
     {
         return;
     }
     _scoreContext.Add(submitScore);
     await _scoreContext.SaveChangesAsync();
 }
コード例 #2
0
        public async Task <IActionResult> CreateScore(long id, [FromBody] ScoreInputModel scoreInput)
        {
            if (scoreInput == null)
            {
                return(BadRequest());
            }

            if (id == 0)
            {
                return(NotFound());
            }

            var leaderboardExists = await _context.Leaderboards.AnyAsync(l => l.Id == id);

            if (!leaderboardExists)
            {
                return(NotFound());
            }

            // TODO: More validation e.g. minimum length.
            if (scoreInput.Name == null)
            {
                return(BadRequest());
            }

            // TODO: More validation e.g. allowed ranges.
            if (!scoreInput.Value.HasValue)
            {
                return(BadRequest());
            }

            Score score = new Score {
                LeaderboardId = id, Name = scoreInput.Name, Value = scoreInput.Value.Value
            };
            // TEMPORARY HACK WHILE WE ARE USING IN-MEMORY DATABASE
            long maxId = await _context.Scores.Select(s => s.Id).MaxAsync();

            score.Id = maxId + 1;

            _context.Add(score);
            await _context.SaveChangesAsync();

            return(CreatedAtRoute("GetScore", new { id = score.Id }, score));
        }
コード例 #3
0
        public void Add(int scoreTable, int userId)
        {
            var score = new ScoreTable()
            {
                score = scoreTable, users_id = userId
            };

            scoreContext.Add(score);
            scoreContext.SaveChanges();
        }
コード例 #4
0
        public void Add(string Name)
        {
            var User = new User()
            {
                name = Name
            };

            scoreContext.Add(User);
            scoreContext.SaveChanges();
        }
コード例 #5
0
        public async Task <IActionResult> Create([Bind("ScoreId,StudentId,CourseId,TimeScore,PointScore")] Score score)
        {
            if (ModelState.IsValid)
            {
                _scoreContext.Add(score);
                await _scoreContext.SaveChangesAsync();

                return(RedirectToAction("Index", "Scores", new { id = score.CourseId }));
            }
            return(View(score));
        }
コード例 #6
0
        public Window_Gameover(long tScore)
        {
            _Score = tScore;
            ScoreContext _scoreContext = new ScoreContext();
            Score        score         = new Score();

            score.ScoreId    = DateTimeOffset.Now.ToUnixTimeMilliseconds();
            score.ScoreValue = (int)tScore;
            _scoreContext.Add(score);
            _scoreContext.SaveChanges();
            InitializeComponent();
        }
コード例 #7
0
        public ActionResult <Game> Create(Game game)
        {
            using var gameDataContext = new GameDataContext();
            using var matchContext    = new MatchContext();
            long id = (gameDataContext.GameDatas.Max(m => (int?)m.Id) ?? 0) + 1;

            game.Id = id;
            if (game.Date == null)
            {
                game.Date = DateTime.Now.ToString("u", System.Globalization.CultureInfo.InvariantCulture);
            }
            gameDataContext.Add(new GameData {
                Id   = id,
                Date = game.Date,
            });
            gameDataContext.SaveChanges();
            var matches = new List <Match>();

            foreach (var player in game.Team1)
            {
                matches.Add(new Match
                {
                    GameId = id,
                    Player = player,
                    Team   = 1,
                });
            }
            foreach (var player in game.Team2)
            {
                matches.Add(new Match
                {
                    GameId = id,
                    Player = player,
                    Team   = 2,
                });
            }
            matchContext.AddRange(matches);
            matchContext.SaveChanges();
            using var scoreContext = new ScoreContext();
            float?result = null;

            if (game.Score == '1')
            {
                result = 1;
            }
            else if (game.Score == '2')
            {
                result = 0;
            }
            else if (game.Score == 'D')
            {
                result = 0.5f;
            }
            else if (game.Score == 'C')
            {
                result = -1;
            }
            scoreContext.Add(new Score
            {
                GameId = id,
                Result = result,
            });
            scoreContext.SaveChanges();
            return(CreatedAtAction(nameof(GetById), new { id = id }, game));
        }