public List <Track> GetTracksByUri(string query)
 {
     if (new Regex("^urn:artist:(.*):track$").IsMatch(query))
     {
         var matches = new Regex("(urn:artist:)(.*)(:track)").Split(query);
         return(this.GetTracksByArtist(matches[2]));
     }
     if (new Regex("^urn:artist:(.*):album$").IsMatch(query))
     {
         var matches = new Regex("(urn:artist:)(.*)(:album)").Split(query);
         return(this.GetTracksByArtist(matches[2]));
     }
     if (new Regex("^urn:artist:(.*):album:(.*):track$").IsMatch(query))
     {
         var    matches = new Regex("(urn:artist:)(.*)(:album:)(.*)(:track)$").Split(query);
         string artist  = matches[2];
         string album   = matches[4];
         return(this.GetTracksByAlbumFromArtist(artist, album));
     }
     if (new Regex("urn:search:(.*)").IsMatch(query))
     {
         var q = query.Substring("urn:search:".Length);
         using (BungalowDatabaseContext dbContext = new BungalowDatabaseContext())
         {
             var tracks = dbContext.Tracks.SqlQuery("SELECT * FROM Tracks WHERE Name LIKE '%" + q + "%' OR Artist LIKE '%" + q + "%' OR Album LIKE '%" + q + "%'");
             return(tracks.ToList());
         }
     }
     return(new List <Track>());
 }
 public List <Track> GetTracksByAlbumFromArtist(string artist, string album)
 {
     using (BungalowDatabaseContext dbContext = new BungalowDatabaseContext())
     {
         var tracks = dbContext.Tracks.OrderBy((t) => t.Name).OrderBy((t) => t.Album).OrderBy((t) => t.Artist).Where((t) => t.Album == album).Where((t) => t.Artist == artist);
         return(tracks.ToList());
     }
 }
 public List <Track> GetAllTracks()
 {
     using (BungalowDatabaseContext dbContext = new BungalowDatabaseContext())
     {
         var tracks = dbContext.Tracks.OrderBy((t) => t.Name).OrderBy((t) => t.Album).OrderBy((t) => t.Artist);
         return(tracks.ToList());
     }
 }
 private void Bw_DoWork(object sender, DoWorkEventArgs e)
 {
     using (DbContext = new BungalowDatabaseContext())
     {
         ScanDirectory(textBox1.Text);
         DbContext.SaveChanges();
     }
     bw.ReportProgress(100);
 }
 public bool Play(string name, string artist, string album)
 {
     using (BungalowDatabaseContext mdb = new BungalowDatabaseContext())
     {
         try
         {
             var item = (from t in mdb.Tracks where t.Name == name && t.Artist == artist && t.Album == album select t.Url).First();
             Bungalow.URL = item;
             Bungalow.Ctlcontrols.play();
             return(true);
         }
         catch (Exception e)
         {
             return(false);
         }
     }
 }
        public List <Artist> GetAllArtists()
        {
            using (BungalowDatabaseContext dbContext = new BungalowDatabaseContext())
            {
                List <Artist> artists  = new List <Artist>();
                var           xartists = dbContext.Database.SqlQuery <string>("SELECT DISTINCT Artist from Tracks ORDER BY Artist ASC");

                foreach (string t in xartists)
                {
                    var artist = new Artist()
                    {
                        Name = t
                    };
                    artists.Add(artist);
                }
                return(artists.ToList());
            }
        }
        public List <Album> GetAlbumsByArtist(string artist)

        {
            using (BungalowDatabaseContext dbContext = new BungalowDatabaseContext())
            {
                var          xalbums = dbContext.Database.SqlQuery <string>("SELECT DISTINCT Album FROM tracks WHERE artist = '" + artist.Replace("'", "") + "'");
                List <Album> albums  = new List <Album>();
                foreach (string salbum in xalbums)
                {
                    Album album = new Album()
                    {
                        Name = salbum
                    };
                    albums.Add(album);
                }
                return(albums);
            }
        }