Spotify.NET/SpotifyAPI.Web.Examples/Example.ASP/Pages/Index.cshtml.cs

46 lines
1.2 KiB
C#
Raw Normal View History

2022-11-27 12:29:35 +00:00
using System.Threading.Tasks;
2020-05-22 11:23:25 +01:00
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;
2023-05-27 21:20:33 +01:00
public Paging<FullPlaylist> Playlists { get; set; }
2020-05-22 11:23:25 +01:00
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 });
}
}
}
}