示例#1
0
 public GameModel(Game game)
 {
     this.Id = game.Id;
     this.Name = game.Name;
     this.Blue = "No blue player yet";
     //this.Red = game.RedPlayer.UserName;
     this.GameState = game.State;
     this.DateCreated = game.DateCreated;
     this.Number = game.RedNumber;
 }
示例#2
0
 public GameDetailModel(Game game)
 {
     this.Id = game.Id;
     this.Name = game.Name;
     this.DateCreaded = game.DateCreated;
     this.Red = game.RedPlayer.UserName;
     if (game.BluePlayer != null)
     {
         this.Blue = game.BluePlayer.UserName;
     }
     else
     {
         this.Blue = "No blue player yet";
     }
     this.YourNumber = game.RedNumber;
     this.YourGuesses = game.Guesses.AsQueryable()
         .Where(g=>g.UserId == game.RedPlayerId)
         .Select(GuessModel.FromGuess).ToArray();
     this.OpponentGuesses = game.Guesses.AsQueryable()
         .Where(g => g.UserId != game.RedPlayerId)
         .Select(GuessModel.FromGuess).ToArray();
 }
示例#3
0
        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);
        }