예제 #1
0
        public IHttpActionResult GameStatus(GameStatusBindingModel model)
        {
            if (model == null)
            {
                this.ModelState.AddModelError("model", "The model is empty");
            }

            if (!ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var guidGameId = new Guid(model.GameId);
            var game       = this.Data.Games
                             .All()
                             .FirstOrDefault(g => g.Id == guidGameId);

            if (game == null)
            {
                return(this.NotFound());
            }

            var userId = this.userIdProvider.GetUserId();

            if (game.PlayerOneId != userId && game.PlayerTwoId != userId)
            {
                return(this.BadRequest("You can't check the status of this game!"));
            }

            return(this.Ok(game.Field));
        }
        public IHttpActionResult GameStatus(GameStatusBindingModel model)
        {
            if (model == null)
            {
                this.ModelState.AddModelError("model", "The model is empty");
            }

            if (!ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var guidGameId = new Guid(model.GameId);
            var game = this.Data.Games
                .All()
                .FirstOrDefault(g => g.Id == guidGameId);
            if (game == null)
            {
                return this.NotFound();
            }

            var userId = this.userIdProvider.GetUserId();
            if (game.PlayerOneId != userId && game.PlayerTwoId != userId)
            {
                return this.BadRequest("You can't check the status of this game!");
            }

            return this.Ok(game.Field);
        }