private static void CreateUserIfNotExist(DiabloContext context, IEnumerable<XElement> xUsers)
 {
     foreach (var xUser in xUsers)
     {
         var userName = xUser.Attribute("username").Value;
         Console.WriteLine(userName);
     }
 }
 // nope
 static void Main()
 {
     var context = new DiabloContext();
     var xmlDoc = XDocument.Load(@"..\..\users-and-games.xml");
     var userNodes = xmlDoc.XPathSelectElements("/users/user");
     foreach (var userNode in userNodes)
     {
         //CreateUserIfNotExist(context, userNode);
     }
 }
 static void Main()
 {
     var context = new DiabloContext();
     var characterNames = context.Characters
         .Select(c => c.Name)
         .ToList();
     foreach (var charName in characterNames)
     {
         Console.WriteLine(charName);
     }
 }
 static void Main()
 {
     var context = new DiabloContext();
     var charsPlayers = context.Characters
         .OrderBy(c => c.Name)
         .Select(c => new
         {
             name = c.Name,
             playedBy = c.UsersGames
                 .Select(u => u.User.Username)
         })
         .ToList();
     var jsSerializer = new JavaScriptSerializer();
     var charsPlayersJson = jsSerializer.Serialize(charsPlayers);
     File.WriteAllText("characters.json", charsPlayersJson);
     Console.WriteLine("Characted and Players exported to characters.json");
 }
        static void Main()
        {
            var context = new DiabloContext();
            var finishedGames = context.Games
                .Where(g => g.IsFinished == true)
                .OrderBy(g => g.Name)
                .ThenBy(g => g.Duration)
                .Select(g => new
                {
                    Name = g.Name,
                    Duration = g.Duration,
                    Users = g.UsersGames
                        .Select(u => new
                        {
                            UserName = u.User.Username,
                            IPAddress = u.User.IpAddress
                        })
                        .ToList()
                })
                .ToList();

            var gamesXml = new XElement("games");
            foreach (var finishedGame in finishedGames)
            {
                var gameXml = new XElement("game");
                gameXml.Add(new XAttribute("name", finishedGame.Name));
                if (finishedGame.Duration.HasValue)
                {
                    gameXml.Add(new XAttribute("duration", finishedGame.Duration));
                }
                var usersXml = new XElement("users");

                foreach (var user in finishedGame.Users)
                {
                    var userXml = new XElement("user");
                    userXml.Add(new XAttribute("username", user.UserName));
                    userXml.Add(new XAttribute("ip-address", user.IPAddress));
                    usersXml.Add(userXml);
                }
                gameXml.Add(usersXml);
                gamesXml.Add(gameXml);
            }
            var xmlDocument = new XDocument(gamesXml);
            xmlDocument.Save("finished-games.xml");
            Console.WriteLine("Finished Games exported to finished-games.xml.");
        }