Esempio n. 1
0
        public async Task <Player> Create(NewPlayer player)
        {
            Player newPlayer = new Player();
            Guid   playerId  = Guid.NewGuid();

            newPlayer.Id           = playerId;
            newPlayer.Name         = player.Name;
            newPlayer.CreationTime = DateTime.Now;
            newPlayer.Level        = 0;
            newPlayer.Score        = 0;
            newPlayer.IsBanned     = false;

            await _collection.InsertOneAsync(newPlayer);

            return(newPlayer);
        }
Esempio n. 2
0
        public Task <Player> Create(NewPlayer np)
        {
            return(Task.Run(() => {
                Player newPlayer = new Player();
                Guid playerId = Guid.NewGuid();

                newPlayer.Id = playerId;
                newPlayer.Name = np.Name;
                newPlayer.CreationTime = DateTime.Now;
                newPlayer.Level = 0;
                newPlayer.Score = 0;
                newPlayer.IsBanned = false;

                string jsonData = System.IO.File.ReadAllText(dataFilePath);

                PlayersList players = JsonConvert.DeserializeObject <PlayersList>(jsonData);

                PlayersList addPlayer;

                if (players != null)
                {
                    addPlayer = new PlayersList(players.players.Length + 1);

                    for (int i = 0; i < players.players.Length; i++)
                    {
                        addPlayer.players[i] = players.players[i];
                    }
                    addPlayer.players[players.players.Length] = newPlayer;
                }
                else
                {
                    addPlayer = new PlayersList(1);
                    addPlayer.players[0] = newPlayer;
                }

                var json = JsonConvert.SerializeObject(addPlayer, Formatting.Indented);

                System.IO.File.WriteAllText(dataFilePath, json);
                Console.WriteLine("(CREATE) Player created: " + newPlayer.Id);

                return newPlayer;
            }));
        }
Esempio n. 3
0
 public Task <Player> Create([FromBody] NewPlayer player)
 {
     return(_repository.Create(player));
 }