예제 #1
0
        public async Task <IActionResult> Post(PlayerReqVM playerReqVM)
        {
            if (ModelState.IsValid)
            {
                PlayerDto playerDto = mapper.Map <PlayerReqVM, PlayerDto>(playerReqVM);

                playerDto = await playerManager.CreateAsync(playerDto);

                if (playerDto.Id == Guid.Empty)
                {
                    ModelState.AddModelError("Player", $"Failed to create player - {playerReqVM.Name}");

                    return(BadRequest(ModelState));
                }

                PlayerCreatedRespVM playerCreatedRespVM = new PlayerCreatedRespVM()
                {
                    Id   = playerDto.Id,
                    Href = $"/api/v1/Players/{playerDto.Id}"
                };

                return(Created(playerCreatedRespVM.Href, playerCreatedRespVM));
            }

            return(BadRequest(ModelState));
        }
        public async Task <IActionResult> Create([FromBody] PlayerRequest request)
        {
            var result = await _playerManager.CreateAsync(request);

            return(Ok(new ApiResponse(_localizationService, _logger).Ok(_mapper.Map <Player, PlayerResponse>(result))));
        }