public async Task <ActionResult <EpisodeWithValidUntilClaim> > GetCurrentClaimedEpisode() { try { User user = await _auth.GetUserFromValidToken(Request); EpisodeWithValidUntilClaim claimedEpisode = await _claim.GetUserByClaimedEpisodeAsync(user.Id); if (claimedEpisode == null) { return(BadRequest("Currently there are no claimed episodes by this user.")); } return(Ok(claimedEpisode)); } catch (TokenDoesNotExistException e) { return(Unauthorized()); } catch (Exception e) { if (e.Message.Contains("Sequence contains no elements")) { return(BadRequest("Currently there are no claimed episodes by this user.")); } _logger.LogError($"Error while trying to get the episode the user currently has claimed. Error:\n{e.Message}"); SentrySdk.CaptureException(e); } return(Problem()); }
public async Task <EpisodeWithValidUntilClaim> GetClaimedEpisode() { try { HttpResponseMessage response = null; using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, $"{_httpClient.BaseAddress}Claim")) { requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", (await _userSession.GetToken()).AccessToken); response = await _httpClient.SendAsync(requestMessage); } if (response.IsSuccessStatusCode) { string json = response.Content.ReadAsStringAsync().Result; EpisodeWithValidUntilClaim ep = JsonSerializer.Deserialize <EpisodeWithValidUntilClaim>(json); return(ep); } } catch (Exception e) { SentrySdk.CaptureException(e); } return(null); }
protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { EpisodeWithValidUntilClaim claimedEpisode = await _data.GetClaimedEpisode(); if (claimedEpisode == null) { return; } if (claimedEpisode.Id == episodeId) { ClaimValidUntil = claimedEpisode.valid_until; ValidTimeRemainingTimer = new System.Timers.Timer(1000); ValidTimeRemainingTimer.Elapsed += CountDownTimer; ValidTimeRemainingTimer.Enabled = true; } } }
public async Task <bool> IsCurrentlyClaimedEpisode(int episodeId) { if (!await _userSession.IsLoggedInAsync()) { return(false); } try { EpisodeWithValidUntilClaim ep = await GetClaimedEpisode(); if (ep == null) { return(false); } return(ep.Id == episodeId); } catch (Exception e) { return(false); } }