public void a_AddToPlaylist()
        {
            string result = null;

            try
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    PlaylistMusic pm = new PlaylistMusic {
                        Id = -1, MusicId = -1, PlaylistId = -1
                    };
                    context.PlaylistMusics.Add(pm);

                    context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT dbo.PlaylistMusic ON;");
                    context.SaveChanges();
                    context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT dbo.PlaylistMusic OFF;");

                    transaction.Commit();

                    result = "ok";
                }
            }
            catch (Exception e)
            {
                result = e.ToString();
            }

            Assert.True(result == "ok", result);
        }
        public IActionResult AddToPlaylist(int playlist_id, int music_id)
        {
            TempData["ConfirmationResult"] = new string[] { "danger", "Une erreur s'est produite lors de l'ajout à une playlist." };
            if (UserOwnsPlaylist(playlist_id)) // If user owns this playlist
            {
                IEnumerable <PlaylistMusic> listPM = contextPlaylist.PlaylistMusics.ToList().Where(pm => (pm.PlaylistId == playlist_id) && (pm.MusicId == music_id));
                if (!listPM.Any()) // Check if music_id isn't already in playlist_id
                {
                    PlaylistMusic pm = new PlaylistMusic()
                    {
                        MusicId = music_id, PlaylistId = playlist_id
                    };

                    contextPlaylist.PlaylistMusics.Add(pm);
                    contextPlaylist.SaveChanges();

                    TempData["ConfirmationResult"] = new string[] { "success", "La musique a été ajoutée à la playlist avec succès !" };
                }
                else
                {
                    TempData["ConfirmationResult"] = new string[] { "warning", "La musique est déjà dans cette playlist." };
                }
            }
            else
            {
                TempData["ConfirmationResult"] = new string[] { "danger", "La playlist est introuvable." };
            }

            return(RedirectToAction("Index"));
        }
        public static bool CreatePM(PlaylistMusic pm)
        {
            var en = new ProjectNCTEntities();

            en.PlaylistMusics.Add(pm);
            return(en.SaveChanges() > 0 ? true : false);
        }
Esempio n. 4
0
 public IHttpActionResult CreatePlaylistMusic(PlaylistMusic playlistMusic)
 {
     if (new Repositories().CreatePlaylistMusic(playlistMusic))
     {
         return(Ok());
     }
     return(InternalServerError());
 }
Esempio n. 5
0
        //public PlaylistMusicDTO GetIdMusicByIdPlaylist(int id)
        //{
        //    var data = new PlaylistMusicDao().GetMusicByIdPlaylist(id);
        //    return new PlaylistMusicDTO
        //    {
        //        ID = data
        //    };

        //}

        public bool CreatePlaylistMusic(PlaylistMusic playlistMusic)
        {
            if (new PlaylistMusicDao().CreatePlaylist(playlistMusic))
            {
                return(true);
            }
            return(false);
        }
Esempio n. 6
0
 public bool CreatePlaylist(PlaylistMusic playlistMusic)
 {
     db.PlaylistMusics.Add(playlistMusic);
     if (db.SaveChanges() > 0)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 7
0
        private void AddToPlaylist_Executed(object obj)
        {
            foreach (var song in SelectedGlobalMusic)
            {
                if (!PlaylistMusic.Any(s => s.Id == song.Id))
                {
                    this.PlaylistMusic.Add(song);
                }
            }

            UpdatePlaylistMusicCollection();
        }
Esempio n. 8
0
        // POST api/<controller>
        public IHttpActionResult Post(PlaylistMusicView s)
        {
            var item = new PlaylistMusic {
                ID = s.ID, MusicID = s.MusicID, PlaylistID = s.PlaylistID
            };
            var res = Repositories.CreatePM(item);

            if (res == true)
            {
                return(Ok());
            }
            return(InternalServerError());
        }
Esempio n. 9
0
        public IActionResult RemoveFromPlaylist(int playlist_id, int music_id)
        {
            string userId = User.FindFirstValue(ClaimTypes.NameIdentifier); // Get actual user id
            IEnumerable <Playlist> usersPlaylist = context.Playlists.ToList().Where(p => (p.AudioPlayerProjectUserId == userId) && (p.Id == playlist_id));

            if (usersPlaylist.Any()) // If user owns this playlist
            {
                PlaylistMusic pm = context.PlaylistMusics.Where(pm => (pm.PlaylistId == playlist_id && (pm.MusicId == music_id))).First();
                context.PlaylistMusics.Remove(pm);
                context.SaveChanges();
            }

            return(RedirectToAction("Show", new { id = playlist_id }));
        }
Esempio n. 10
0
        private void RemoveFromPlaylist_Executed(object obj)
        {
            var selecteditems = SelectedPlaylistMusic.ToList();

            foreach (var song in selecteditems)
            {
                if (PlaylistMusic.Any(s => s.Id == song.Id))
                {
                    this.PlaylistMusic.Remove(song);
                }
            }

            UpdatePlaylistMusicCollection();
        }
Esempio n. 11
0
        public async Task <bool> AddSong(Playlists list, PlaylistMusic song)
        {
            if (list != null)
            {
                var update = await _context.Playlists.UpdateOneAsync(new BsonDocument("_id", list._id),
                                                                     Builders <Playlists> .Update.Push("songs", song));

                if (update.ModifiedCount == 1)
                {
                    return(true);
                }
                return(false);
            }
            return(false);
        }
        public void b_RemoveFromPlaylist()
        {
            string result = null;

            try
            {
                PlaylistMusic pm = context.PlaylistMusics.Find(-1);
                context.PlaylistMusics.Remove(pm);
                context.SaveChanges();
                result = "ok";
            }
            catch (Exception e)
            {
                result = e.ToString();
            }

            Assert.True(result == "ok", result);
        }
Esempio n. 13
0
        public JsonResult OnGet(int playlistId, int musicId)
        {
            PlaylistMusic playlistMusic = _db.playlistMusic.Where(p => p.music_id == musicId && p.playlist_id == playlistId).FirstOrDefault();

            if (playlistMusic != null)
            {
                _db.playlistMusic.Remove(playlistMusic);
                _db.SaveChanges();

                return(new JsonResult(new RequestStatus {
                    status = true, message = "Song deleted from playlist"
                }));
            }

            return(new JsonResult(new RequestStatus {
                status = false, message = "Couldn't delete song from playlist"
            }));
        }
Esempio n. 14
0
        public JsonResult OnPost([FromForm] PlaylistMusic playlistMusic)
        {
            if (_db.playlistMusic.Any(p => p.music_id == playlistMusic.music_id && p.playlist_id == playlistMusic.playlist_id))
            {
                return(new JsonResult(new RequestStatus {
                    status = false, message = "This song already exists in given playlist"
                }));
            }

            _db.playlistMusic.Add(playlistMusic);

            if (_db.SaveChanges() > 0)
            {
                return(new JsonResult(new RequestStatus {
                    status = true, message = "Song added to playlist!"
                }));
            }

            return(new JsonResult(new RequestStatus {
                status = false, message = "Couldn't add song to playlist"
            }));
        }
Esempio n. 15
0
 public void Update(PlaylistMusic item)
 {
     DbSet.AddOrUpdate(item);
 }
Esempio n. 16
0
        private void ClearPlaylist_Executed(object obj)
        {
            PlaylistMusic.Clear();

            UpdatePlaylistMusicCollection();
        }
Esempio n. 17
0
 public static bool CreatePM(PlaylistMusic pm)
 {
     return(MusicBUS.CreatePM(pm));
 }
Esempio n. 18
0
 private bool AddToPlayer_CanExecute(object arg)
 {
     return(PlaylistMusic.Any());
 }
Esempio n. 19
0
 private bool ClearPlaylist_CanExecute(object arg)
 {
     return(PlaylistMusic.Any());
 }
Esempio n. 20
0
 public void Create(PlaylistMusic item)
 {
     DbSet.Add(item);
 }