public IHttpActionResult Create(GameModel model)
{
var userId = this.User.Identity.GetUserId();
var redPlayer = this.data.Users.Find(userId);
var newGame = new Game
{
Name = model.Name,
DateCreated = DateTime.Now,
RedPlayerId = userId,
RedPlayer = redPlayer,
//BluePlayerId = null,
RedNumber = model.Number,
//BlueNumber = null,
State = GameState.WaitingForOpponent
};
this.data.Games.Add(newGame);
this.data.SaveChanges();
// Make new Guess on creating the game
this.Guess(newGame.Id, new GuessModel { Number = newGame.RedNumber });
var gameModel = new GameModel(newGame);
gameModel.Red = redPlayer.UserName;
// Send notification to the creator of the game
string notificationMessage = "You have created new game with Name: " + newGame.Name;
SendNotification(newGame.Id, userId, "GameCreated", notificationMessage);
return Ok(gameModel);
}