예제 #1
0
        public async Task <Player> ModifyPlayer(Guid PlaythroughId, Guid Playerid, ModifiedPlayer Player)
        {
            Playthrough Playthrough = await this.GetPlaythrough(PlaythroughId);

            Player newPlayer = new Player();

            newPlayer.kills  = Player.kills;
            newPlayer.deaths = Player.deaths;

            Player[] PlayerList = Playthrough.Players.ToArray();
            for (int i = 0; i < PlayerList.Count(); i++)
            {
                if (PlayerList[i].id == Playerid)
                {
                    newPlayer.id   = PlayerList[i].id;
                    newPlayer.Name = PlayerList[i].Name;
                    PlayerList[i]  = newPlayer;
                }
            }
            Playthrough.Players = PlayerList.ToList();

            await _collection.ReplaceOneAsync(Builders <Playthrough>
                                              .Filter.Eq("id", PlaythroughId), Playthrough);

            return(newPlayer);
        }
예제 #2
0
        public async Task <Player[]> GetAllPlayers(Guid PlaythroughId)
        {
            /* var filter = Builders<Playthrough>.Filter.Eq ("id", PlaythroughId);
             * Playthrough Playthrough1 = (PlayThrough)_collection.Find (filter); */
            Playthrough Playthrough1 = await this.GetPlaythrough(PlaythroughId);

            return(Playthrough1.Players.ToArray());
        }
예제 #3
0
        public async Task <Playthrough> DeletePlaythrough(Guid PlaythroughId)
        {
            var filter = Builders <Playthrough> .Filter.Eq("id", PlaythroughId);

            Playthrough Playthrough = await _collection.Find(filter).FirstAsync();

            _collection.DeleteOneAsync(filter);
            return(Playthrough);
        }
예제 #4
0
        public async Task <Playthrough> ModifyPlaythrough(Guid id, Playthrough Playthrough)
        {
            var filter = Builders <Playthrough> .Filter.Eq("id", id);

            Playthrough Playthrough1 = await this.GetPlaythrough(id);

            Playthrough1.Players = Playthrough.Players;
            await _collection.ReplaceOneAsync(filter, Playthrough1);

            return(Playthrough1);
        }
예제 #5
0
        public async Task <Player> CreatePlayer(Guid PlaythroughId, Player Player)
        {
            Playthrough tempPT = new Playthrough();

            tempPT = await this.GetPlaythrough(PlaythroughId);

            tempPT.Players.Add(Player);
            var filter = Builders <Playthrough> .Filter.Eq("id", PlaythroughId);

            await _collection.ReplaceOneAsync(filter, tempPT);

            /*  var filter = Builders<Playthrough>.Filter.Eq("id", PlaythroughId);
             * var update =  Builders<Playthrough>.Update.Push("Players", Player);
             * await _collection.FindOneAndUpdateAsync(filter, update); */
            return(Player);
        }
예제 #6
0
        public async Task <Player> GetPlayer(Guid PlaythroughId, Guid Playerid)
        {
            var filter = Builders <Playthrough> .Filter.Eq("id", PlaythroughId);

            Playthrough Playthrough = await _collection.Find(filter).FirstAsync();

            //Playthrough Playthrough = await this.GetPlaythrough(PlaythroughId);
            Player[] PlayerList = Playthrough.Players.ToArray();
            foreach (var Player in PlayerList)
            {
                if (Player.id == Playerid)
                {
                    return(Player);
                }
            }
            return((Player)null);
        }
예제 #7
0
        public async Task <Playthrough> CreatePlaythrough(NewPlaythrough Playthrough)
        {
            Playthrough createePlaythrough = new Playthrough();

            createePlaythrough.id           = Guid.NewGuid();
            createePlaythrough.CreationTime = DateTime.Now;
            Player warrior = new Player(), ranger = new Player(), wizard = new Player();

            warrior.Name = "Warrior";
            warrior.id   = Guid.NewGuid();
            ranger.Name  = "Ranger";
            ranger.id    = Guid.NewGuid();
            wizard.Name  = "Wizard";
            wizard.id    = Guid.NewGuid();
            createePlaythrough.Players.Add(warrior);
            createePlaythrough.Players.Add(ranger);
            createePlaythrough.Players.Add(wizard);
            return(await IP.CreatePlaythrough(createePlaythrough));
        }
예제 #8
0
        public async Task <Player> DeletePlayer(Guid PlaythroughId, Guid Playerid)
        {
            Playthrough Playthrough = await this.GetPlaythrough(PlaythroughId);

            List <Player> PlayerList = Playthrough.Players;
            Player        temp       = null;

            for (int i = 0; i < PlayerList.Count(); i++)
            {
                if (PlayerList[i].id == Playerid)
                {
                    temp = PlayerList[i];
                    PlayerList.Remove(PlayerList[i]);
                }
            }
            Playthrough.Players = PlayerList;
            await _collection.ReplaceOneAsync(Builders <Playthrough>
                                              .Filter.Eq("id", PlaythroughId), Playthrough);

            return(temp);
        }
예제 #9
0
 public Task <Playthrough> ModifyPlaythrough(Guid PlaythroughID, [FromBody] Playthrough Playthrough)
 {
     return(IP.ModifyPlaythrough(PlaythroughID, Playthrough));
 }
예제 #10
0
        public async Task <Playthrough> CreatePlaythrough(Playthrough Playthrough)
        {
            await _collection.InsertOneAsync(Playthrough);

            return(Playthrough);
        }