public async Task <HttpResponseMessage> Get(string projectId) { Watch project = await _watchProjectRepository.GetByIdAsync( projectId, UserId); // Post-processing if (User.IsInRole(DomainRoles.User)) { try { project.IsLiked = await _projectLikesService.IsLikedAsync(projectId, UserId); project.IsDisliked = await _projectLikesService.IsDislikedAsync(projectId, UserId); } catch (Exception e) { Trace.TraceError("Failed to get like state for project '{0}': {1}", project.Id, e); } } // For statistics Request.Properties.Add("isReady", project.State == WatchState.Ready); return(Request.CreateResponse(HttpStatusCode.OK, project)); }
public async Task <ActionResult> Index(string id) { // Social bots if (_userAgentVerifier.IsSocialBot(Request.UserAgent) && ContainsOverrideParams()) { VideoModel videoModel = GetVideoModel(id); return(View("OgTags", videoModel)); } // Get video Watch project; try { project = await _watchProjectRepository.GetByIdAsync(id, UserId); // Post-processing if (User.IsInRole(DomainRoles.User)) { project.IsLiked = await _projectLikesService.IsLikedAsync(id, UserId); project.IsDisliked = await _projectLikesService.IsDislikedAsync(id, UserId); } // For statistics HttpContext.Items.Add("isReady", project.State == WatchState.Ready); } catch (ForbiddenException) { // Go home if forbidden return(RedirectToAction("Index", "Home")); } catch (NotFoundException) { return(HttpNotFound()); } catch (UnauthorizedException) { // Go home if unauthorized // In case user is unauthorized we should show him 401-error-page. // But there isn't one so for now it would be redirect on Home page. return(RedirectToAction("Index", "Home")); } catch (Exception e) { Trace.TraceError("Failed to retrieve project {0}: {1}", id, e); return(HttpNotFound()); } VideoModel model = await GetVideoModel(project, id); // Get current user avatar url DomainUser user = null; try { user = await _userService.GetAsync(UserId); } catch (NotFoundException) { } model.UserAvatarUrl = _userAvatarProvider.GetAvatar(user); // Show banners for non-mobile devices if (!_userAgentVerifier.IsMobileDevice(Request.UserAgent)) { ViewBag.VideoViewBanner = _settings.VideoViewBanner; } return(View("Index", model)); }