Beispiel #1
0
 internal static Player UpdatePlayerFromDTO(Player player, FullPlayerDTO playerDTO)
 {
     player.Name = playerDTO.Name;
     player.Nick = playerDTO.Nick;
     player.City = playerDTO.City;
     return(player);
 }
Beispiel #2
0
 public async Task <ActionResult> AddPlayer([FromBody] FullPlayerDTO player)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (await _playerService.AddPlayer(player))
     {
         return(Created(String.Empty, null));
     }
     else
     {
         return(BadRequest());
     }
 }
        public async Task <bool> EditPlayer(Guid id, FullPlayerDTO playerDTO)
        {
            var entity = await _playersRepository.GetPlayerAsync(id);

            if (entity == null)
            {
                return(false);
            }
            else
            {
                await _playersRepository.Update(Mapper.UpdatePlayerFromDTO(entity, playerDTO));

                return(true);
            }
        }
Beispiel #4
0
 public async Task <ActionResult> Editplayer(Guid id, [FromBody] FullPlayerDTO player)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (await _playerService.EditPlayer(id, player))
     {
         return(Ok());
     }
     else
     {
         ModelState.AddModelError("Błąd", "nie znaleziono ID");
         return(NotFound(ModelState));
     }
 }
        public IHttpActionResult Get()
        {
            var principal = Request.GetRequestContext().Principal as ClaimsPrincipal;

            if (principal == null)
            {
                return(BadRequest());
            }

            var accountNameClaim = principal.Claims.FirstOrDefault(x => x.Type == "userName");

            if (accountNameClaim == null)
            {
                return(BadRequest());
            }

            var playerName = accountNameClaim.Value.ToString();

            if (string.IsNullOrWhiteSpace(playerName))
            {
                return(BadRequest());
            }

            Player player = _playerRepository.GetByAccountName(playerName);

            if (player != null)
            {
                var playerDto = new FullPlayerDTO()
                {
                    _id         = player._id,
                    name        = player.AccountName,
                    email       = player.Email,
                    joinDate    = player.JoinDate,
                    displayName = player.DisplayName
                };
                return(Ok(playerDto));
            }
            else
            {
                return(NotFound());
            }
        }
        public async Task <bool> AddPlayer(FullPlayerDTO player)
        {
            var players = await _playersRepository.GetPlayersAsync();

            if (players.Any(x => x.Name == player.Name && x.Nick == player.Nick))
            {
                return(false);
            }
            else
            {
                await _playersRepository.Create(new Player(
                                                    Guid.NewGuid(),
                                                    player.Name,
                                                    player.Nick,
                                                    player.City
                                                    ));

                return(true);
            }
        }
 public bool EditPlayer(Guid id, FullPlayerDTO player)
 {
     throw new NotImplementedException();
 }
 public bool AddPlayer(FullPlayerDTO player)
 {
     throw new NotImplementedException();
 }