コード例 #1
0
        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);
        }
コード例 #2
0
        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"));
        }
コード例 #3
0
        public static bool CreatePM(PlaylistMusic pm)
        {
            var en = new ProjectNCTEntities();

            en.PlaylistMusics.Add(pm);
            return(en.SaveChanges() > 0 ? true : false);
        }
コード例 #4
0
 public IHttpActionResult CreatePlaylistMusic(PlaylistMusic playlistMusic)
 {
     if (new Repositories().CreatePlaylistMusic(playlistMusic))
     {
         return(Ok());
     }
     return(InternalServerError());
 }
コード例 #5
0
ファイル: PlaylistMusicBus.cs プロジェクト: akakshuki/nctFake
        //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);
        }
コード例 #6
0
ファイル: PlaylistMusicDao.cs プロジェクト: akakshuki/nctFake
 public bool CreatePlaylist(PlaylistMusic playlistMusic)
 {
     db.PlaylistMusics.Add(playlistMusic);
     if (db.SaveChanges() > 0)
     {
         return(true);
     }
     return(false);
 }
コード例 #7
0
ファイル: CommandContext.cs プロジェクト: KaynePlan/YAM
        private void AddToPlaylist_Executed(object obj)
        {
            foreach (var song in SelectedGlobalMusic)
            {
                if (!PlaylistMusic.Any(s => s.Id == song.Id))
                {
                    this.PlaylistMusic.Add(song);
                }
            }

            UpdatePlaylistMusicCollection();
        }
コード例 #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());
        }
コード例 #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 }));
        }
コード例 #10
0
ファイル: CommandContext.cs プロジェクト: KaynePlan/YAM
        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();
        }
コード例 #11
0
ファイル: PlaylistOperator.cs プロジェクト: otokatari/backend
        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);
        }
コード例 #12
0
        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);
        }
コード例 #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"
            }));
        }
コード例 #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"
            }));
        }
コード例 #15
0
 public void Update(PlaylistMusic item)
 {
     DbSet.AddOrUpdate(item);
 }
コード例 #16
0
ファイル: CommandContext.cs プロジェクト: KaynePlan/YAM
        private void ClearPlaylist_Executed(object obj)
        {
            PlaylistMusic.Clear();

            UpdatePlaylistMusicCollection();
        }
コード例 #17
0
 public static bool CreatePM(PlaylistMusic pm)
 {
     return(MusicBUS.CreatePM(pm));
 }
コード例 #18
0
ファイル: CommandContext.cs プロジェクト: KaynePlan/YAM
 private bool AddToPlayer_CanExecute(object arg)
 {
     return(PlaylistMusic.Any());
 }
コード例 #19
0
ファイル: CommandContext.cs プロジェクト: KaynePlan/YAM
 private bool ClearPlaylist_CanExecute(object arg)
 {
     return(PlaylistMusic.Any());
 }
コード例 #20
0
 public void Create(PlaylistMusic item)
 {
     DbSet.Add(item);
 }