Пример #1
0
 public Player(CreatePlayerDTO dto)
 {
     this.Id   = new Guid(dto.Id);
     this.Name = dto.Name;
     this.Gold = dto.Gold;
     this.Ap   = dto.Ap;
 }
Пример #2
0
        public Player CreatePlayer(CreatePlayerDTO PlayerDTO)
        {
            try
            {
                var ExistingTeam = _teamRepository.FindById(new Guid(PlayerDTO.TeamId));

                if (ExistingTeam == null)
                {
                    return(null);
                }

                Player newPlayer = PlayerDTO.toPlayer();
                _playerRepository.Create(newPlayer);
                _playerRepository.Save();

                NotifyAll(newPlayer);

                return(newPlayer);
            }
            catch (Exception ex)
            {
                _logger.LogWarning($"{ex.Message}\r\n{ex.StackTrace}");
                return(null);
            }
        }
Пример #3
0
        public static Player toPlayer(this CreatePlayerDTO createPlayerDTO)
        {
            DateTime PlayerBirthdate = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);

            PlayerBirthdate = PlayerBirthdate.AddSeconds(createPlayerDTO.Birthdate).ToLocalTime();

            return(new Player
            {
                Name = createPlayerDTO.Name,
                Role = createPlayerDTO.Role,
                Birthdate = PlayerBirthdate,
                MatchesPlayed = createPlayerDTO.MatchesPlayed,
                TeamId = new Guid(createPlayerDTO.TeamId)
            });
        }
Пример #4
0
        public ActionResult <Player> AddPlayer([FromBody] CreatePlayerDTO createPlayerDTO)
        {
            if (createPlayerDTO.TeamId == null)
            {
                return(BadRequest("Missing team id"));
            }

            Player Result = _playerService.CreatePlayer(createPlayerDTO);

            if (Result == null)
            {
                return(BadRequest("An error has occurred."));
            }

            return(Ok(Result));
        }