Esempio n. 1
0
        public void AddPlaylist(Playlist playlist, int userId)
        {
            int ID = userId;

            using (var context = new CloudMp3SQLContext())
            {
                playlist.P_OwnerId = ID;
                context.Playlists.Add(playlist);
                context.SaveChanges();
                GetPlaylistsForUser(ID);
            }
        }
Esempio n. 2
0
        public int GetUserID(string usrName)
        {
            int id;

            using (var context = new CloudMp3SQLContext())
            {
                var query = (from u in context.Users
                             where u.U_UserName == usrName
                             select u).SingleOrDefault();
                id = query.U_Id;
            }
            return(id);
        }
Esempio n. 3
0
        public void UploadSong(string filePath, int userID)
        {
            using (var context = new CloudMp3SQLContext())
            {
                using (var tran = context.Database.BeginTransaction())
                {
                    try
                    {
                        isCompleted = false;
                        string         fileName  = Path.GetFileName(filePath);
                        TagLib.File    tagFile   = TagLib.File.Create(filePath);
                        CloudBlockBlob blockBlob = _container.GetBlockBlobReference(fileName);
                        var            user      = (from u in context.Users
                                                    where u.U_Id == userID
                                                    select u).SingleOrDefault();
                        string s = "";
                        if (tagFile.Tag.Title == null)
                        {
                            s = fileName.Replace(".mp3", "");
                        }
                        else
                        {
                            s = tagFile.Tag.Title;
                        }
                        Song newSong = new Song()
                        {
                            S_Artist  = tagFile.Tag.FirstPerformer,
                            S_Length  = (int)tagFile.Properties.Duration.TotalMilliseconds,
                            S_Title   = s,
                            S_OwnerId = userID,
                            S_Path    = blobStorageUri + blockBlob.Uri.AbsolutePath
                        };
                        Console.WriteLine(newSong.S_Path);
                        user.Songs.Add(newSong);

                        using (var fileStream = System.IO.File.OpenRead(filePath))
                        {
                            blockBlob.UploadFromStream(fileStream);
                            isCompleted = true;
                        }
                        isCompleted = false;
                        context.SaveChanges();
                        tran.Commit();
                    }
                    catch (Exception)
                    {
                        tran.Rollback();
                    }
                }
            }
        }
Esempio n. 4
0
        public void RenamePlaylist(int playlistId, int userId, string newName)
        {
            int ID = userId;

            using (var context = new CloudMp3SQLContext())
            {
                Playlist playlistQuery = (from p in context.Playlists
                                          where p.P_Id == playlistId
                                          where p.P_OwnerId == ID
                                          select p).First();
                playlistQuery.P_Name = newName;
                context.SaveChanges();
                GetPlaylistsForUser(ID);
            }
        }
Esempio n. 5
0
 public void RemoveSongFromPlaylist(int songId, int playlistId)
 {
     using (var context = new CloudMp3SQLContext())
     {
         Song songQuery = (from s in context.Songs
                           where s.S_Id == songId
                           select s).First();
         Playlist playlistQuery = (from p in context.Playlists
                                   where p.P_Id == playlistId
                                   select p).First();
         songQuery.Playlists.Remove(playlistQuery);
         playlistQuery.Songs.Remove(songQuery);
         context.SaveChanges();
         GetSongsInPlaylist(playlistQuery.P_Id);
     }
 }
Esempio n. 6
0
        public ObservableCollection <Playlist> GetPlaylistsForUser(int userId)
        {
            ObservableCollection <Playlist> userPlaylists = new ObservableCollection <Playlist>();

            using (var context = new CloudMp3SQLContext())
            {
                var query = (from p in context.Playlists
                             where p.P_OwnerId == userId
                             select p).ToList <Playlist>();
                foreach (Playlist x in query)
                {
                    userPlaylists.Add(x);
                }
            }
            return(userPlaylists);
        }
Esempio n. 7
0
        public ObservableCollection <Song> GetSongsInPlaylist(int playlistId)
        {
            ObservableCollection <Song> playlistSongs = new ObservableCollection <Song>();

            using (var context = new CloudMp3SQLContext())
            {
                var query = (from p in context.Playlists
                             where p.P_Id == playlistId
                             select p.Songs).SingleOrDefault();

                foreach (Song x in query)
                {
                    playlistSongs.Add(x);
                }
            }
            return(playlistSongs);
        }
Esempio n. 8
0
        public ObservableCollection <Song> GetSongsForUser(int userId)
        {
            ObservableCollection <Song> userSongs = new ObservableCollection <Song>();

            using (var context = new CloudMp3SQLContext())
            {
                var query = (from s in context.Songs
                             where s.S_OwnerId == userId
                             select s).ToList <Song>();
                foreach (Song x in query)
                {
                    userSongs.Add(x);
                }
            }
            userSongs = new ObservableCollection <Song>(userSongs.OrderBy(s => s.S_Artist));
            return(userSongs);
        }
Esempio n. 9
0
        public void AddSongToPlaylist(int songId, int playlistId)
        {
            using (var context = new CloudMp3SQLContext())
            {
                Song song = (from s in context.Songs
                             where s.S_Id == songId
                             select s).SingleOrDefault();

                Playlist playlist = (from p in context.Playlists
                                     where p.P_Id == playlistId
                                     select p).SingleOrDefault();

                //songQuery.Playlists.Add(playlistQuery);
                playlist.Songs.Add(song);
                context.SaveChanges();
            }
        }
Esempio n. 10
0
 public void ValidateUserName(string usrName, string pass)
 {
     using (var context = new CloudMp3SQLContext())
     {
         var query = (from u in context.Users
                      where u.U_UserName == usrName
                      select u).SingleOrDefault();
         if (query == null)
         {
             User u = new User();
             u.U_UserName = usrName;
             u.U_Password = pass;
             context.Users.Add(u);
             context.SaveChanges();
         }
     }
     this.Close();
 }
Esempio n. 11
0
        public void RemovePlaylist(int playlistId, int userId)
        {
            int ID = userId;

            using (var context = new CloudMp3SQLContext())
            {
                Playlist playlistQuery = (from p in context.Playlists
                                          where p.P_Id == playlistId
                                          select p).First();
                foreach (Song s in playlistQuery.Songs)
                {
                    s.Playlists.Remove(playlistQuery);
                }
                context.Playlists.Remove(playlistQuery);
                context.SaveChanges();
                GetPlaylistsForUser(ID);
            }
        }
Esempio n. 12
0
        public bool ValidateUserName(string usrName, string pass)
        {
            bool valid = false;

            using (var context = new CloudMp3SQLContext())
            {
                var query = (from u in context.Users
                             where u.U_UserName == usrName
                             select u).SingleOrDefault();
                if (query != null)
                {
                    if (pass == query.U_Password)
                    {
                        valid = true;
                    }
                }
            }
            return(valid);
        }