/*
         * Adds a media to the database
         */
        private void AddMediaButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = fileTypeFilter;
            if (openFileDialog.ShowDialog() == true)
            {
                try
                {
                    FileStream file = File.Open(openFileDialog.FileName, FileMode.Open);
                    using (var db = new mainEntities())
                    {
                        string fileExt  = Path.GetExtension(file.Name).Remove(0, 1);
                        string fileType = extensions[fileExt];
                        Medias newMedia = new Medias
                        {
                            Name   = Path.GetFileNameWithoutExtension(file.Name),
                            Ext    = fileExt,
                            ExtID  = (from ext in db.MediaExtensions where ext.Extension == fileExt select ext).Single <MediaExtensions>().Id,
                            Path   = file.Name,
                            Type   = fileType,
                            TypeID = (from type in db.MediaTypes where type.Name == fileType select type).Single <MediaTypes>().Id
                        };
                        db.Medias.Add(newMedia);
                        db.SaveChanges();
                        Populate();
                        file.Close();
                        db.Dispose();
                    }
                } catch (IOException) { }
            }
        }
 /*
  * Removes every medias from the database
  */
 private void RemoveAllButton_Click(object sender, RoutedEventArgs e)
 {
     using (var db = new mainEntities())
     {
         db.Medias.RemoveRange(from media in db.Medias select media);
         db.SaveChanges();
         selectionList.Clear();
         Populate();
         db.Dispose();
     }
 }
 /*
  * Removes the selected medias from the database
  */
 private void RemoveButton_Click(object sender, RoutedEventArgs e)
 {
     using (var db = new mainEntities())
     {
         foreach (Medias m in selectionList)
         {
             db.Medias.RemoveRange(from media in db.Medias where media.Id == m.Id select media);
         }
         db.SaveChanges();
         selectionList.Clear();
         Populate();
         db.Dispose();
     }
 }