public async Task <IActionResult> PutAsync(int score) { if (score < 0) { ModelState.AddModelError("score", "Parameter is missing or value is negative"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var id = User.Identity.GetUserIdentity(); var ev = new ScoreAdded { Id = _board.NewId(), UserId = id, Score = score, Timestamp = DateTimeOffset.Now, }; await _eventStore.AppendEventAsync(ev); return(StatusCode(204)); }
public override void AddNumber(int score) { var path = $@"..\{Name}.txt"; using (StreamWriter sr = File.AppendText(path)) { sr.WriteLine(score); ScoreAdded?.Invoke(this, new EventArgs()); sr.Close(); } if (score == 0) { var zeroWarningPath = $@"C:\Users\T430\Desktop\Damian\Scores\{Name}.txt"; using (StreamWriter sr = File.AppendText(zeroWarningPath)) { sr.WriteLine($"score, added {DateTime.UtcNow}"); ZeroScoreWarning?.Invoke(this, new EventArgs()); sr.Close(); } } }
/// <summary> /// Adds a new high score, sorts and keeps top 10, saves to disk. /// </summary> public void AddHighScore(string initials, int score) { HighScore hs = new HighScore(initials, score); lock (this) { _scores.Add(hs); _scores = _scores.OrderByDescending(s => s.Score).Take(_maxCount).ToList(); SaveLocalFile(_localFile, _scores); } ScoreAdded?.InvokeFromTask(hs); }
public override void AddNumber(int input) { if (input >= 0 && input <= 100) { _scores.Add(input); //jeżeli ScoreAdded jest nullem to znaczy, że nikt nie nasłuchuje tego eventu //this informuje, że to ta metoda wywołuje ten event ScoreAdded?.Invoke(this, new EventArgs()); } else { throw new ArgumentException($"Invalid argument {nameof(input)}"); } }
public void AddScore(object sender, PositionEventArgs e) { switch (e.Position) { case PlayerPosition._1: Score += 2; break; case PlayerPosition._2: Score += 3; break; default: throw new NotImplementedException(); } ScoreAdded?.Invoke(this, new EventArgs()); }
public void AddScore() { _score++; ScoreAdded?.Invoke(_score); }