static void Main(string[] args)
        {
            var context = new DiabloEntities();

            XDocument xmlDoc = XDocument.Load("../../../../users-and-games.xml");

            var usersElements = xmlDoc.Root.Elements();

            foreach (var userElement in usersElements)
            {
                var userEntity = new User();
                userEntity.Username = userElement.Attribute("username").Value;
                string registrationDate = userElement.Attribute("registration-date").Value;
                userEntity.RegistrationDate = DateTime.ParseExact(registrationDate, "dd/mm/yyyy", CultureInfo.InstalledUICulture);
                userEntity.IpAddress = userElement.Attribute("ip-address").Value;
                userEntity.IsDeleted = userElement.Attribute("is-deleted").Value == "1";
                if (userElement.Attribute("first-name") != null)
                {
                    userEntity.FirstName = userElement.Attribute("first-name").Value;
                }
                if (userElement.Attribute("last-name") != null)
                {
                    userEntity.FirstName = userElement.Attribute("last-name").Value;
                }
                if (userElement.Attribute("email") != null)
                {
                    userEntity.FirstName = userElement.Attribute("email").Value;
                }

                context.Users.Add(userEntity);
                Console.WriteLine("Successfully added user {0}", userEntity.Username);

                context.SaveChanges();
            }
        }
        static void Main(string[] args)
        {
            var context = new DiabloEntities();

            var characterNames = context.Characters
                .Select(c => c.Name);

            foreach (var characterName in characterNames)
            {
                Console.WriteLine(characterName);
            }
        }
        static void Main(string[] args)
        {
            var context = new DiabloEntities();

            var finishedGames = context.Games
                .OrderBy(g => g.Name)
                .ThenBy(g => g.Duration)
                .Where(g => g.IsFinished == true)
                .Select(g => new
                {
                    Name = g.Name,
                    Duration = g.Duration != null ? g.Duration : null,
                    Users = g.UsersGames.Select(ug => new
                    {
                        Username = ug.User.Username,
                        IpAddress = ug.User.IpAddress
                    })
                });

            var xmlDoc = new XDocument();
            var xmlRoot = new XElement("games");
            xmlDoc.Add(xmlRoot);

            foreach (var game in finishedGames)
            {
                var gamesXmlElement = new XElement("game");
                var gameXmlaNameAttribute = new XAttribute("name", game.Name);
                gamesXmlElement.Add(gameXmlaNameAttribute);
                if(game.Duration != null)
                {
                    var gameXmlDurationAtrribute = new XAttribute("duration", game.Duration);
                    gamesXmlElement.Add(gameXmlDurationAtrribute);
                }

                var usersXmlElement = new XElement("users");
                foreach (var user in game.Users)
                {
                    var userXmlElement = new XElement("user");
                    var userXmlUsernameAttribute = new XAttribute("username", user.Username);
                    var userXmlIpAdressAttribute = new XAttribute("ip-address", user.IpAddress);
                    userXmlElement.Add(userXmlUsernameAttribute);
                    userXmlElement.Add(userXmlIpAdressAttribute);
                    usersXmlElement.Add(userXmlElement);
                }
                gamesXmlElement.Add(usersXmlElement);
                xmlRoot.Add(gamesXmlElement);
            }

            xmlDoc.Save("finished-games.xml");
        }
        static void Main(string[] args)
        {
            var context = new DiabloEntities();

            var charactersAndPlayers = context.Characters
                .OrderBy(c => c.Name)
                .Select(c => new
                {
                    name = c.Name,
                    playedBy = c.UsersGames.Select(ug => ug.User.Username)
                });

            var json = new JavaScriptSerializer().Serialize(charactersAndPlayers);

            File.WriteAllText(@"characters.json", json);
        }