private static void newTextbox_KeyDown( object sender, KeyEventArgs e )
 {
     if (e.Key != Key.Enter)
     {
         return;
     }
     using (var context = new Db1Entities())
     {
         var textBox = sender as TextBox;
         if (textBox != null)
         {
             var encyclopedia = new Encyclopedia
             {
                 Name = textBox.Text
             };
             context.Encyclopedia.Add(encyclopedia);
         }
         context.SaveChanges();
         var box = sender as TextBox;
         if (box != null)
         {
             MessageBox.Show("The Encyclopedia '" + box.Text + "' has been added to the Database");
         }
     }
     var grid = ( (TextBox) sender ).Parent as Grid;
     ( grid?.Parent as Window )?.Close();
 }
        private static void RefreshEncyclopedia( Encyclopedia enc )
        {
            using (var context = new Db1Entities())
            {
                //Races
                var alienlist = ( from c in context.Aliens select c ).ToList();
                var encyclorace = ( from c in context.encycloRace select c ).ToList();

                var result = alienlist.Where(p => encyclorace.All(p2 => p2.RaceName != p.Name)).ToList();
                foreach (var item in result)
                {
                    var insertRace = new encycloRace
                    {
                        EncyclopediaId = enc.Id,
                        RaceName = item.Name,
                        RaceDiscription = "Fill Me!!!"
                    };
                    context.encycloRace.Add(insertRace);
                    context.SaveChanges();
                }
            }
        }
 private void LoadEncyclopedia()
 {
     using (var context = new Db1Entities())
     {
         _loadedEncyclopedia = ( from c in context.Encyclopedia select c ).FirstOrDefault();
         RefreshEncyclopedia(_loadedEncyclopedia);
     }
     //Type t = typeof(encycloPerson);
     //Type z = typeof(encycloFactions);
     //List < Type> typelist = new List<Type>();
     //typelist.Add(t);
     //typelist.Add(z);
     //ccMainCollection.NewItemTypes = typelist;
 }