mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-26 07:56:26 +00:00
46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
|
using System.Threading.Tasks;
|
|||
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|||
|
using SpotifyAPI.Web;
|
|||
|
|
|||
|
namespace Example.ASP.Pages
|
|||
|
{
|
|||
|
public class IndexModel : PageModel
|
|||
|
{
|
|||
|
private const int LIMIT = 10;
|
|||
|
private readonly SpotifyClientBuilder _spotifyClientBuilder;
|
|||
|
|
|||
|
public Paging<SimplePlaylist> Playlists { get; set; }
|
|||
|
|
|||
|
public string Next { get; set; }
|
|||
|
public string Previous { get; set; }
|
|||
|
|
|||
|
public IndexModel(SpotifyClientBuilder spotifyClientBuilder)
|
|||
|
{
|
|||
|
_spotifyClientBuilder = spotifyClientBuilder;
|
|||
|
}
|
|||
|
|
|||
|
public async Task OnGet()
|
|||
|
{
|
|||
|
var spotify = await _spotifyClientBuilder.BuildClient();
|
|||
|
|
|||
|
int offset = int.TryParse(Request.Query["Offset"], out offset) ? offset : 0;
|
|||
|
var playlistRequest = new PlaylistCurrentUsersRequest
|
|||
|
{
|
|||
|
Limit = LIMIT,
|
|||
|
Offset = offset
|
|||
|
};
|
|||
|
Playlists = await spotify.Playlists.CurrentUsers(playlistRequest);
|
|||
|
|
|||
|
if (Playlists.Next != null)
|
|||
|
{
|
|||
|
Next = Url.Page("Index", new { Offset = offset + LIMIT });
|
|||
|
}
|
|||
|
if (Playlists.Previous != null)
|
|||
|
{
|
|||
|
Previous = Url.Page("Index", values: new { Offset = offset - LIMIT });
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|