public Task <Item> UpdateItem(Guid playerId, Guid itemsId, ModifiedItem modifiedItem) { int found = -1; var getPlayers = GetPlayers(); getPlayers.Wait(); Player[] playerList = getPlayers.Result; int length = playerList.Length; for (int i = 0; i < length; i++) { if (playerList[i].Id == playerId) { foreach (var item in playerList[i].Items) { if (item.Id == itemsId) { found = i; item.Level = modifiedItem.Level; PlayerList newPlayerList = new PlayerList(); newPlayerList.Players = playerList; File.WriteAllText(filePath, JsonConvert.SerializeObject(newPlayerList)); return(Task.FromResult(item)); } } } } //return Task.FromException<Item>(new Exception("not found")); throw new NotFoundException(); }
public async Task <Item> UpdateItem(Guid playerId, Guid itemId, ModifiedItem modifiedItem) { Player player = await Get(playerId); foreach (var item in player.Items) { if (item.Id == itemId) { item.Level = modifiedItem.Level; FilterDefinition <Player> filter = Builders <Player> .Filter.Eq(p => p.Id, player.Id); await collection.ReplaceOneAsync(filter, player); return(item); } } throw new NotFoundException(); }
public async Task <Item> Modify(Guid playerId, Guid itemsId, ModifiedItem item) { return(await repository.UpdateItem(playerId, itemsId, item)); }