public async Task <IActionResult> Get(int id, CancellationToken cancellationToken) { var maybeShow = await _showsService.GetShowAsync(id, cancellationToken); if (maybeShow.HasNoValue) { return(NotFound()); } return(Ok(maybeShow.Value)); }
public async Task <IActionResult> OnGetAsync(string show) { showObj = await _show.GetShowAsync(show); episodes = await _episode.GetEpisodesAsync(showObj); Tags = await _tag.GetTagsAsync(showObj); if (showObj.Title == "" || showObj.Title == null) { return(Redirect("/search")); } return(Page()); }
public async Task <IActionResult> OnGetAsync(string show, int epindex) { showObj = await _show.GetShowAsync(show); Episodes = await _episode.GetEpisodesAsync(showObj); episodeObj = await _episode.GetEpisodeAsync(showObj, epindex); Tags = await _tag.GetTagsAsync(showObj); if (episodeObj.Title == null || episodeObj.Title == "") { return(Redirect("/show/" + show)); } await _view.PostViewAsync(showObj, episodeObj); Views = (await _view.GetViewsAsync(episodeObj)).ToString("N0", System.Globalization.CultureInfo.GetCultureInfo("de")); return(Page()); }
public async Task <IActionResult> RateShowAsync(RateShow rateShowWithoutId) { // SHOULDN'T BE DONE THIS WAY // SHOULD CONFIGURE CLAIMS ON IDENTITY TO RETRIEVE USER ID var userId = User.Claims.ToList()[5].Value; var rateShow = new RateShowWithUserId { Rate = rateShowWithoutId.Rate, ShowId = rateShowWithoutId.ShowId, UserId = new Guid(userId), }; if (rateShow.Rate < 1 || rateShow.Rate > 5) { throw new ShowException($"{nameof(rateShow.Rate)} has to be between 1 and 5"); } if (rateShow.ShowId <= 0) { throw new ShowException($"{nameof(rateShow.ShowId)} must be a positive number"); } var show = await _showService.GetShowAsync(rateShow.ShowId); if (show == null) { throw new ShowException($"Show with Id {rateShow.ShowId} does not exist"); } var showRate = await _showRateService.GetShowRateAsync(rateShow.ShowId, rateShow.UserId); if (showRate != null) { var updatedRatedShow = await _showRateService.UpdateRateAsync(rateShow); return(Ok(updatedRatedShow)); } var ratedShow = await _showRateService.RateShowAsync(rateShow); return(Ok(ratedShow)); }