Ejemplo n.º 1
0
        public void HandleRequestAsync(RequestModel requestModel, IOutputBoundary <ResponseModel> outputBoundary)
        {
            _ = requestModel?.PlayerId ?? throw new ArgumentNullException(nameof(requestModel.PlayerId));

            var avitar = AvitarRepository.ReadAsync(requestModel.PlayerId);

            var currentPlayer = new BlackJackPlayer(avitar, HandIdProvider, requestModel.HandCount);

            var keyAndGame = GameRepository.FindByStatusFirstOrDefault(GameStatus.Waiting, requestModel.MaxPlayers);

            string        gameIdentifier;
            BlackJackGame game;

            if (string.IsNullOrEmpty(keyAndGame.Key))
            {
                gameIdentifier = GameIdProviders.GenerateGameId();
                game           = new BlackJackGame(CardProvider, DealerProvider.Dealer, requestModel.MaxPlayers);
            }
            else
            {
                gameIdentifier = keyAndGame.Key;
                game           = keyAndGame.Value;
            }

            game.AddPlayer(currentPlayer);

            GameRepository.UpdateAsync(gameIdentifier, game);

            outputBoundary.HandleResponse(new ResponseModel()
            {
                GameIdentifier = gameIdentifier
            });
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "Avitar"
                         )] HttpRequest req)
        {
            Logger.LogInformation("C# HTTP trigger function processed a request.");

            var avitar = GetAvitarDto(req);
            ItemResponse <AvitarDto> response;

            // TODO This logic is NOT correct.  Need full crud.  right now edit isn't working.
            if (string.IsNullOrWhiteSpace(avitar.id) == false)
            {
                response = await Repository.ReadAsync(avitar);
            }
            else
            {
                avitar.id ??= new GuidBasedAvitarIdentifierProvider().GenerateAvitar();
                response = await Repository.SaveAsync(avitar);
            }

            Logger.LogInformation(response.Headers.ToString());

            return(response?.Resource != null
                                ? (ActionResult) new OkObjectResult($"Hello, {response.Resource.id}: {response.Resource.userName}")
                                : new BadRequestObjectResult("Please pass a name and/or id on the query string or in the request body"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "GetAvitar")] HttpRequest req)
        {
            Logger.LogInformation("C# HTTP trigger function processed a request.");

            string id = req.Query["id"];

            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);

            id = id ?? data?.id;
            var name = await GetNameFromUrlOrBody(req);

            var avitar = new AvitarDto()
            {
                id = id, userName = name
            };
            var response = await Repository.ReadAsync(avitar);

            Logger.LogInformation(response.Headers.ToString());

            return(response != null
                ? (ActionResult) new OkObjectResult($"Hello, {response.Resource.id}: {response.Resource.userName}")
                : new BadRequestObjectResult("Please pass a existing id on the query string or in the request body"));
        }