public async Task <ActionResult> Index(string id) { Watch project; try { // TODO: Hack! we should create separate SPA fro admin. project = await _watchProjectRepository.GetByIdAsync(id, UserId); // For statistics HttpContext.Items.Add("isReady", project.State == WatchState.Ready); } catch (ForbiddenException) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } catch (UnauthorizedException) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } catch (NotFoundException) { return(HttpNotFound()); } catch (Exception e) { Trace.TraceError("Failed to retrieve project {0}: {1}", id, e); return(HttpNotFound()); } return((ActionResult)View("Index", await GetVideoModel(project, id))); }
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 <HttpResponseMessage> Post(string id) { Watch project = await _watchProjectService.GetByIdAsync(id, UserId); // Add to statistics in background Task.Run(() => _cassandraStatisticsService.AddAbuseAsync(StatisticsSpaces.Projects, id, UserId)) .ContinueWith(r => _projectService.IncrementAbuseCounterAsync(id), TaskContinuationOptions.OnlyOnRanToCompletion).NoWarning(); // Send activation e-mail try { DomainUser reporter = await _userService.GetAsync(UserId); await _emailNotificationService.SendAbuseNotificationAsync(project, reporter); } catch (Exception e) { Trace.TraceError("Failed to send abuse report e-mail from user {0}: {1}", UserId, e); } return(Request.CreateResponse(HttpStatusCode.OK)); }
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)); }