2021-10-18 21:48:02 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
2021-10-24 20:15:09 +01:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2021-10-18 21:48:02 +01:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2022-06-22 21:51:38 +01:00
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
using Selector.Model;
|
|
|
|
|
using Selector.Model.Extensions;
|
2021-10-18 21:48:02 +01:00
|
|
|
|
|
|
|
|
|
namespace Selector.Web.Pages
|
|
|
|
|
{
|
2021-10-24 20:15:09 +01:00
|
|
|
|
[AllowAnonymous]
|
2021-10-18 21:48:02 +01:00
|
|
|
|
public class IndexModel : PageModel
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<IndexModel> _logger;
|
2022-06-22 21:51:38 +01:00
|
|
|
|
private readonly UserManager<ApplicationUser> _userManager;
|
|
|
|
|
private readonly IScrobbleRepository _scrobbleRepo;
|
2021-10-18 21:48:02 +01:00
|
|
|
|
|
2022-06-22 21:51:38 +01:00
|
|
|
|
public IndexModel(ILogger<IndexModel> logger, UserManager<ApplicationUser> userManager, IScrobbleRepository scrobbleRepo)
|
2021-10-18 21:48:02 +01:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2022-06-22 21:51:38 +01:00
|
|
|
|
_userManager = userManager;
|
|
|
|
|
_scrobbleRepo = scrobbleRepo;
|
2021-10-18 21:48:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-22 21:51:38 +01:00
|
|
|
|
[BindProperty]
|
|
|
|
|
public int? DailyScrobbles { get; set; }
|
|
|
|
|
|
2021-10-18 21:48:02 +01:00
|
|
|
|
public void OnGet()
|
|
|
|
|
{
|
2022-06-22 21:51:38 +01:00
|
|
|
|
if(User.Identity.IsAuthenticated)
|
|
|
|
|
{
|
|
|
|
|
var user = _userManager.GetUserAsync(User).Result;
|
|
|
|
|
if(user.ScrobbleSavingEnabled())
|
|
|
|
|
{
|
|
|
|
|
DailyScrobbles = _scrobbleRepo.CountToday(userId: user.Id);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-18 21:48:02 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|