Esempio n. 1
0
 public MainSongViewModel(MainSongView mainSongOpen)
 {
     mainSongView   = mainSongOpen;
     Song           = new tblSong();
     SongList       = GetSongs();
     worker.DoWork += WorkerOnDoWork;
 }
 /// <summary>
 /// Constructor with the add song info window opening
 /// </summary>
 /// <param name="addSongOpen">opends the add song window</param>
 public AddSongViewModel(AddSong addSongOpen)
 {
     song                 = new tblSong();
     addSong              = addSongOpen;
     SongList             = service.GetAllSongs().ToList();
     AllCurrentUsersSongs = service.GetAllSongsFromCurrentUser(LoggedUser.CurrentUser.UserID).ToList();
 }
Esempio n. 3
0
        public tblSong AddSong(tblSong song)
        {
            try
            {
                using (AudioPlayerDataEntities context = new AudioPlayerDataEntities())
                {
                    tblSong newSong = new tblSong();

                    newSong.SongName   = song.SongName;
                    newSong.Author     = song.Author;
                    newSong.SongLength = song.SongLength;
                    newSong.UserID     = song.UserID;



                    context.tblSongs.Add(newSong);
                    context.SaveChanges();

                    return(newSong);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
        /// <summary>
        /// Deletes the song depending if the songID already exists
        /// </summary>
        /// <param name="songID">the song that is being deleted</param>
        /// <returns>list of song</returns>
        public void DeleteSong(int songID)
        {
            try
            {
                using (AudioDBEntities context = new AudioDBEntities())
                {
                    bool isSong = IsSongID(songID);
                    if (isSong == true)
                    {
                        tblSong songToDelete = (from r in context.tblSongs where r.SongID == songID select r).First();

                        context.tblSongs.Remove(songToDelete);
                        context.SaveChanges();
                    }
                    else
                    {
                        MessageBox.Show("Cannot delete the song");
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception" + ex.Message.ToString());
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Method that worker does
        /// </summary>
        /// <param name="s"></param>
        private void WriteToFile(tblSong s)
        {
            try
            {
                //writes data about the song that is parameter
                string       path = @"..\..\file.txt";
                StreamWriter sw   = new StreamWriter(path, true);
                sw.WriteLine("{0},Reproduction time START:{1}, Duration(s):{2}, Title:{3}", s.SongID, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss"), s.Duration_s, s.Title);
                sw.Close();
                MessageBox.Show("Title: " + " " + s.Title + " \nAuthor:" + s.Author + " " + "\nSong has started");

                //counting when song if finished =>duration in seconds is deceremnted each second
                int counter = s.Duration_s.GetValueOrDefault();
                while (counter != 0)
                {
                    counter -= 1;
                    Thread.Sleep(1000);
                }
                countdown.Signal();
                //signalin that song is over and writing that to file and showing notification to the user
                if (countdown.IsSet)
                {
                    StreamWriter sw1 = new StreamWriter(path, true);
                    sw1.WriteLine("{0},Reproduction time END:{1}, Duration(s):{2}, Title:{3}", s.SongID, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss"), s.Duration_s, s.Title);
                    sw1.Close();
                    MessageBox.Show("Title: " + " " + s.Title + " \nAuthor:" + s.Author + " " + "\nSong has finished");
                    countdown.Reset();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 6
0
        public AddSongViewModel(AddSong addSongView, string Username)
        {
            view    = addSongView;
            service = new ServiceClass();

            this.UserName = Username;
            Song          = new tblSong();
        }
Esempio n. 7
0
 /// <summary>
 /// Deletes the song from tblSong in the database
 /// </summary>
 /// <param name="song"></param>
 internal void DeleteSong(tblSong song)
 {
     using (AudioPlayerEntities context = new AudioPlayerEntities())
     {
         tblSong songToDelete = (from s in context.tblSongs where s.SongID == song.SongID select s).First();
         context.tblSongs.Remove(songToDelete);
         context.SaveChanges();
     }
 }
Esempio n. 8
0
 /// <summary>
 /// Adds a song to the database.
 /// </summary>
 /// <param name="song"></param>
 /// <param name="user"></param>
 internal void AddSong(tblSong song, int userID)
 {
     using (AudioPlayerEntities context = new AudioPlayerEntities())
     {
         tblSong newSong = new tblSong();
         newSong.SongName          = song.SongName;
         newSong.Author            = song.Author;
         newSong.DurationInSeconds = song.DurationInSeconds;
         newSong.UserID            = userID;
         context.tblSongs.Add(newSong);
         context.SaveChanges();
     }
 }
Esempio n. 9
0
 internal void FinishSong(tblSong song, tblUser user)
 {
     are.WaitOne();
     try
     {
         using (StreamWriter sw = new StreamWriter(@"..\..\MyMusic" + user.UserName + ".txt", true))
         {
             sw.WriteLine("finished playing -" + song.Author + " -" + song.SongName + " -" + DateTime.Now.ToString());
         }
         MessageBox.Show(song.SongName + " finished");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Esempio n. 10
0
 internal void PlaySong(tblSong song, tblUser user)
 {
     try
     {
         using (StreamWriter sw = new StreamWriter(@"..\..\MyMusic" + user.UserName + ".txt", true))
         {
             sw.WriteLine("playing -" + song.Author + " -" + song.SongName + " -" + DateTime.Now.ToString());
         }
         Thread.Sleep(song.DurationInSeconds * 1000);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     are.Set();
 }
Esempio n. 11
0
 /// <summary>
 /// Method for deleting
 /// </summary>
 private void DeleteExecute()
 {
     try
     {
         tblSong          songToDelete     = (from r in context.tblSongs where r.SongID == Song.SongID select r).FirstOrDefault();
         MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure? Song will be deleted", "Delete Confirmation", MessageBoxButton.YesNo);
         //user confirmation
         if (messageBoxResult == MessageBoxResult.Yes)
         {
             context.tblSongs.Remove(songToDelete);
             context.SaveChanges();
             //refreshing list afterwards
             SongList = GetSongs();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
 /// <summary>
 /// Saving new song
 /// </summary>
 private void AddExecute()
 {
     try
     {
         tblSong newSong = new tblSong();
         newSong.Title      = Song.Title;
         newSong.Author     = Song.Author;
         newSong.Duration_s = Song.Duration_s;
         context.tblSongs.Add(newSong);
         context.SaveChanges();
         MessageBox.Show("Song is saved in databse");
         Song = new tblSong();
         //sending signal to the list
         Update = true;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
 private void SaveExecute()
 {
     try
     {
         newSong.userId = user.userId;
         tblSong s = Service.Service.AddNewSong(newSong);
         if (s != null)
         {
             isUpdated = true;
             MessageBox.Show("Song has been succesfully added!");
             addSong.Close();
         }
         else
         {
             MessageBox.Show("Error.Try again.");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Esempio n. 14
0
        public void DeleteSong(int songId)
        {
            try
            {
                using (AudioPlayerDataEntities context = new AudioPlayerDataEntities())
                {
                    tblSong songToDelete = (from u in context.tblSongs
                                            where u.SongID == songId select u).First();


                    context.tblSongs.Remove(songToDelete);



                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
            }
        }
Esempio n. 15
0
 public bool AddSong(tblUser user, vwSong song)
 {
     try
     {
         using (DAN_LEntities context = new DAN_LEntities())
         {
             tblSong newSong = new tblSong();
             newSong.SongName = song.SongName;
             newSong.Author   = song.Author;
             newSong.Duration = song.Duration;
             newSong.UserID   = user.UserID;
             context.tblSongs.Add(newSong);
             context.SaveChanges();
             song.SongID = newSong.SongID;
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
Esempio n. 16
0
 /// <summary>
 /// Method for adding song by user
 /// </summary>
 /// <param name="user">user which is adding song</param>
 /// <param name="song">song for adding</param>
 /// <returns></returns>
 public bool AddSong(vwUser user, vwSong song)
 {
     try
     {
         using (AudioPlayerEntities context = new AudioPlayerEntities())
         {
             tblSong newSong = new tblSong();
             newSong.SongName     = song.SongName;
             newSong.SongAuthor   = song.SongAuthor;
             newSong.SongDuration = song.SongDuration;
             newSong.UserId       = user.UserId;
             context.tblSongs.Add(newSong);
             context.SaveChanges();
             song.SongId = newSong.SongId;
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
Esempio n. 17
0
 public bool CreateSong(vwUser user, vwSong song)
 {
     try
     {
         using (AudioPlayerEntities context = new AudioPlayerEntities())
         {
             tblSong newSong = new tblSong
             {
                 Author   = song.Author,
                 Duration = song.Duration,
                 Name     = song.Name,
                 UserId   = user.UserId
             };
             context.tblSongs.Add(newSong);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
        /// <summary>
        /// method for adding the new article
        /// </summary>
        private void SaveExecute()
        {
            try
            {
                using (Zadatak_50Entities context = new Zadatak_50Entities())
                {
                    tblSong newSong = new tblSong();

                    newSong.Title      = song.Title;
                    newSong.Author     = song.Author;
                    newSong.Duration_s = song.Duration_s;
                    newSong.Logged     = song.Logged;
                    newSong.SongID     = song.SongID;

                    context.tblSongs.Add(newSong);
                    context.SaveChanges();
                }
                addNewSong.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Wrong inputs, please try again.");
            }
        }
        /// <summary>
        /// Creates a song
        /// </summary>
        /// <param name="song">the song that is being added</param>
        /// <returns>a new song</returns>
        public tblSong AddSong(tblSong song)
        {
            try
            {
                using (AudioDBEntities context = new AudioDBEntities())
                {
                    if (song.SongID == 0)
                    {
                        tblSong newSong = new tblSong
                        {
                            SongName    = song.SongName,
                            SongAuthor  = song.SongAuthor,
                            SongSeconds = song.SongSeconds,
                            SongMinutes = song.SongMinutes,
                            SongHours   = song.SongHours,
                            UserID      = LoggedUser.CurrentUser.UserID
                        };

                        context.tblSongs.Add(newSong);
                        context.SaveChanges();
                        song.SongID = newSong.SongID;

                        return(song);
                    }
                    else
                    {
                        return(song);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
 public AddSongViewModel(AddSong addSongOpen, tblUser user)
 {
     addSong   = addSongOpen;
     this.user = user;
     newSong   = new tblSong();
 }
 public CreateSongViewModel(CreateSong createSongOpen)
 {
     createSong = createSongOpen;
     Song       = new tblSong();
 }
Esempio n. 22
0
 public AddSongViewModel(AddSongView mainOpen)
 {
     main = mainOpen;
     Song = new tblSong();
 }
 public AddNewSongViewModel(AddNewSong addNewSongOpen)
 {
     song       = new tblSong();
     addNewSong = addNewSongOpen;
 }
Esempio n. 24
0
 public AddSongViewModel(AddSong addSongOpen, tblUser user)
 {
     userToView = user;
     song       = new tblSong();
     addSong    = addSongOpen;
 }
Esempio n. 25
0
 public AddSongViewModel(AddSong addSongView)
 {
     view    = addSongView;
     service = new ServiceClass();
     Song    = new tblSong();
 }