public async Task <IEnumerable <Playlist> > GetPlaylists(ePlaylistScope playlistScope, bool include_relations = false) { // Get current user var current_user = await user_manager.GetUserAsync(http_context.HttpContext.User); IQueryable <Entities.Playlist> includeQuery; if (include_relations) { includeQuery = mintplayer_context.Playlists .Include(p => p.Tracks) .ThenInclude(track => track.Song) .ThenInclude(s => s.Media) .ThenInclude(m => m.Type) .Include(p => p.User); } else { includeQuery = mintplayer_context.Playlists; } IQueryable <Entities.Playlist> scopedQuery; switch (playlistScope) { case ePlaylistScope.My: scopedQuery = includeQuery .Where(p => p.User == current_user); break; case ePlaylistScope.Public: scopedQuery = includeQuery .Where(p => p.Accessibility == MintPlayer.Dtos.Enums.ePlaylistAccessibility.Public); break; default: throw new ArgumentException(nameof(playlistScope)); } return(scopedQuery.Select(p => ToDto(p, include_relations))); }
public async Task <IEnumerable <Playlist> > GetPlaylists(ePlaylistScope playlistScope, bool include_relations = false) { var playlists = await playlistRepository.GetPlaylists(playlistScope, include_relations); return(playlists); }
public async Task <PaginationResponse <Playlist> > PagePlaylists(PaginationRequest <Playlist> request, ePlaylistScope playlistScope) { var playlists = await playlistRepository.PagePlaylists(request, playlistScope); return(playlists); }
public async Task <Pagination.PaginationResponse <Playlist> > PagePlaylists(Pagination.PaginationRequest <Playlist> request, ePlaylistScope playlistScope) { var user = await user_manager.GetUserAsync(http_context.HttpContext.User); IQueryable <Entities.Playlist> playlists; switch (playlistScope) { case ePlaylistScope.My: playlists = mintplayer_context.Playlists .Where(p => p.User == user); break; case ePlaylistScope.Public: playlists = mintplayer_context.Playlists .Where(p => p.Accessibility == MintPlayer.Dtos.Enums.ePlaylistAccessibility.Public); break; default: throw new ArgumentException(nameof(playlistScope)); } // 1) Sort var ordered_playlists = request.SortDirection == System.ComponentModel.ListSortDirection.Descending ? playlists.OrderByDescending(request.SortProperty) : playlists.OrderBy(request.SortProperty); // 2) Page var paged_playlists = ordered_playlists .Skip((request.Page - 1) * request.PerPage) .Take(request.PerPage); // 3) Convert to DTO var dto_playlists = await paged_playlists.Select(p => ToDto(p, false)).ToListAsync(); var count_playlists = await playlists.CountAsync(); return(new Pagination.PaginationResponse <Playlist>(request, count_playlists, dto_playlists)); }