Example #1
0
        public async Task <Item> CreateItem(Guid playerId, Item item)
        {
            Item[]   items;
            Listaaja itemlist = JsonConvert.DeserializeObject <Listaaja>(path);

            items    = new Item[itemlist.ItemList.Length + 2];
            playerId = new Guid();
            var createdItem = new Item
            {
                Id           = item.Id,
                Name         = item.Name,
                level        = item.level,
                type         = item.type,
                creationtime = item.creationtime
            };

            items = itemlist.ItemList;
            items[itemlist.ItemList.Length] = createdItem;
            string itemjson = JsonConvert.SerializeObject(item) + Environment.NewLine;

            try
            {
                await File.AppendAllTextAsync(path, itemjson, Encoding.UTF8);


                return(item);
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
        }
Example #2
0
        public async Task <Player> Create(Player player)
        {
            Player[] players;
            Listaaja playerList = JsonConvert.DeserializeObject <Listaaja>(path);

            players = new Player[playerList.Playerlist.Length + 2];
            var createplayer = new Player
            {
                Id           = player.Id,
                Name         = player.Name,
                Score        = player.Score,
                Level        = player.Level,
                IsBanned     = player.IsBanned,
                CreationTime = player.CreationTime
            };

            players = playerList.Playerlist;
            players[playerList.Playerlist.Length] = createplayer;
            string playerjson = JsonConvert.SerializeObject(player) + Environment.NewLine;

            try
            {
                await File.AppendAllTextAsync(path, playerjson, Encoding.UTF8);


                return(player);
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
        }
Example #3
0
        public Task <Player[]> GetAll()
        {
            Listaaja playerList = JsonConvert.DeserializeObject <Listaaja>(path);

            Player[] player = playerList.Playerlist;
            return(Task.FromResult <Player[]>(player));
        }
Example #4
0
        public Task <Item[]> GetAllItems(Guid playerId)
        {
            Listaaja itemList = JsonConvert.DeserializeObject <Listaaja>(path);

            Item[] item = itemList.ItemList;
            if (path.Contains(playerId.ToString()))
            {
                return(Task.FromResult <Item[]>(item));
            }
            else
            {
                return(null);
            }
        }