public async Task OnGetAsync() { string userId = _userManager.GetUserId(HttpContext.User); Door = await _databaseQueries.GetTodaysDoor(DateTime.Today); if (Door == null) { return; } var firstTimeOpeningDoor = await _databaseQueries.GetFirstTimeOpeningDoor(userId, Door.Id); if (firstTimeOpeningDoor == null) { await _databasePersister.RegisterFirstTimeOpeningDoor(userId, Door); TimeWhenDoorWasOpened = DateTime.Now; } else { TimeWhenDoorWasOpened = firstTimeOpeningDoor.When; RegisteredAnswers = (await _databaseQueries.GetRegisteredAnswersForDoor(userId, Door.Id)) .Select(x => new RegisteredAnswerViewModel { When = x.When, Country = x.Country, Location = x.Location }) .ToList(); } }
public async Task <IActionResult> OnGetAsync(string?returnUrl = null) { // Clear the existing external cookie to ensure a clean login process await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme); ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); ReturnUrl = returnUrl; TodaysDoor = (await _databaseQueries.GetTodaysDoor(DateTime.Today)); NextDoor = (await _databaseQueries.GetNextDoor(DateTime.Today)); if (TodaysDoor == null) { return(Page()); } bool hasOpenedTodaysDoor = await _databaseQueries.HasOpenedDoor(_userManager.GetUserId(HttpContext.User), TodaysDoor.Id); if (hasOpenedTodaysDoor) { return(LocalRedirect(Url.GetLocalUrl("/Doors/Today"))); } return(Page()); }