Exemplo n.º 1
0
        public bool AddSong(string url, int profileId)
        {
            DBSong     dbSong     = new DBSong();
            DbActivity dbActivity = new DbActivity();

            using (IDbTransaction tran = DbConnection.GetInstance().BeginTransaction())
            {
                try
                {
                    Song song = dbSong.FindSongByURL(url);
                    if (song != null)
                    {
                        return(false);
                    }

                    int activityId = dbActivity.CreateActivity(profileId);
                    if (activityId > 0 && dbSong.AddSong(GetVideoTitle(url), GetVideoDuration(url), url, activityId) > 0)
                    {
                        tran.Commit();
                        return(true);
                    }
                    else
                    {
                        tran.Rollback();
                        return(false);
                    }
                }
                catch (Exception)
                {
                    tran.Rollback();
                    return(false);
                }
            }
        }
Exemplo n.º 2
0
        public void FindSongByNameExisting()
        {
            string name = "Idiot Test";

            songController.AddSong("YWo4qBnSwjM", 1);
            songController.AddSong("2a4Uxdy9TQY", 1);
            List <string> urlsActual   = new List <string>();
            List <string> urlsExpected = new List <string>();

            urlsExpected.Add("YWo4qBnSwjM");
            urlsExpected.Add("2a4Uxdy9TQY");

            List <Song> songs = songController.FindSongsByName(name);

            foreach (Song song in songs)
            {
                urlsActual.Add(song.Url);
            }
            CollectionAssert.AreEqual(urlsExpected, urlsActual);
            dbActivity.DeleteActivity(1, dbSong.FindSongByURL("YWo4qBnSwjM", null, new DbConnection().GetConnection()).ActivityId, null, new DbConnection().GetConnection());
            dbActivity.DeleteActivity(1, dbSong.FindSongByURL("2a4Uxdy9TQY", null, new DbConnection().GetConnection()).ActivityId, null, new DbConnection().GetConnection());
        }