示例#1
0
        public async Task <ActionResult <PlayListInfoDTO> > Get([FromRoute]  Guid id)
        {
            PlayListInfoDTO response = await _playListService.GetPlayList(id);

            if (response == null)
            {
                return(NotFound());
            }

            return(response);
        }
示例#2
0
        public async Task <PlayListInfoDTO> GetPlayList(Guid id)
        {
            PlayListInfoDTO response = new PlayListInfoDTO();

            try
            {
                PlayList playList = await _dbContext.PlayLists
                                    .Include(p => p.PlayListMusics)
                                    .Where(p => p.Id == id).SingleOrDefaultAsync();



                if (playList != null)
                {
                    List <Music> musics = await _dbContext.Musics.ToListAsync();

                    List <Music> musicsPlayList = (from music in musics
                                                   join play in playList.PlayListMusics
                                                   on music.Id equals play.MusicId
                                                   select new Music
                    {
                        Id = music.Id,
                        Title = music.Title,
                        Duration = music.Duration,
                        AlbumId = music.AlbumId
                    }).ToList();
                    response.Title       = playList.Title;
                    response.Description = playList.Description;
                    response.musics      = musicsPlayList;
                }
            }
            catch
            {
                response = null;
            }

            return(response);
        }