public void MakeGuess(string guess) { GuessMade e = new GuessMade(Guid.NewGuid().ToString(), this.Id, guess, this.Level); e.Handle(this); PublishEvent(e); if (CurrentRiddle.Solution.Trim().Equals(guess)) { bool completed = this.Level == MaxLevel; int nextLevel = completed ? this.Level : this.Level + 1; IEvent levelSucceeded = new LevelSucceeded(this.Id, this.Level, nextLevel, this.Score + 1 * Level, e.GuessId); levelSucceeded.Handle(this); PublishEvent(levelSucceeded); if (completed) { IEvent gameCompleted = new GameCompleted(this.Id); gameCompleted.Handle(this); PublishEvent(gameCompleted); } } else { int newScore = (this.Score - 1) < 0 ? 0 : this.Score - 1; IEvent levelFailed = new LevelFailed(this.Id, newScore, e.GuessId); levelFailed.Handle(this); PublishEvent(levelFailed); } }
private void Handle(GuessMade e) { GuessReadModel guessRM = new GuessReadModel() { GameId = e.GameId, GuessStatus = "unknown", Guess = e.Guess, Id = e.GuessId, Level = e.Level, GuessTime = DateTime.UtcNow }; this._context.Guesses.Add(guessRM); this._context.SaveChanges(); }