public async Task <JsonNetResult> ByUser(GetUserVideosViewModel model) { // If no user was specified, default to the current logged in user Guid?userId = model.UserId ?? User.GetCurrentUserId(); if (userId == null) { ModelState.AddModelError(string.Empty, "No user specified and no user currently logged in."); return(JsonFailure()); } UserVideos userVideos = await _videoCatalog.GetUserVideos(new GetUserVideos { UserId = userId.Value, PageSize = model.PageSize, PagingState = model.PagingState }); // TODO: Better solution than client-side JOINs Task <UserProfile> authorTask = _userManagement.GetUserProfile(userId.Value); var videoIds = new HashSet <Guid>(userVideos.Videos.Select(v => v.VideoId)); Task <IEnumerable <PlayStats> > statsTask = _stats.GetNumberOfPlays(videoIds); await Task.WhenAll(authorTask, statsTask); return(JsonSuccess(new UserVideosViewModel { UserId = userVideos.UserId, Videos = userVideos.Videos.Join(statsTask.Result, v => v.VideoId, s => s.VideoId, (v, s) => VideoPreviewViewModel.FromDataModel(v, authorTask.Result, s, Url)) .ToList(), PagingState = userVideos.PagingState })); }
public async Task <IActionResult> OnGet(string id, string commentId) { if (!cookieService.Authenticated) { return(Redirect(cookieService.Url("/Home/SignIn/" + encryptionService.EncryptString("/Stream/Archive/" + id + "/" + commentId)))); } CurrentUserProfile = await cookieService.GetCurrentUser(); Video = await storageService.Get <Video>(SQLQueries.GetArchivedStreamsWithStreamId, id); UserProfile = await storageService.Get <Profile>(SQLQueries.GetUserWithUsername, Video.Username); UserChannel = await storageService.Get <Channel>(SQLQueries.GetUserChannelWithUsername, Video.Username); UserChannel.StreamSubjectIcon = MiscHelperMethods.GetCorrespondingSubjectThumbnail(Video.StreamSubject); ChatInfo = encryptionService.EncryptString(Video.Id); FollowValue = await followService.IsFollowingFollowee(CurrentUserProfile.Id, UserProfile.Id); UserVideos = await storageService.GetList <Video>(SQLQueries.GetArchivedStreamsWithUsername, new string[] { UserProfile.Username }); OtherVideos = await storageService.GetList <Video>(SQLQueries.GetRandomArchivedStreams, new string[] { }); RelatedTutors = (await storageService.GetList <Profile>(SQLQueries.GetAllTutorsNotInTheList, new string[] { UserProfile.Id })).GetRange(0, 5); Sections = profileService.GetSections(UserProfile); Schedule = await scheduleService.GetSchedule(UserProfile); Comments = await commentService.GetAllComments(Video.Id); NumberOfStreams = UserVideos.Count; NumberOfFollowers = await followService.GetNumberOfFollowers(UserProfile.Id); NumberOfViews = UserVideos.Sum(x => x.Views); Notifications = await notificationService.GetNotifications(CurrentUserProfile.Username); if (!string.IsNullOrEmpty(commentId)) { NotificationRequestComment = await storageService.Get <Comment>(SQLQueries.GetCommentWithId, commentId); } AreThereUnseenNotifications = await notificationService.AreThereUnseenNotifications(CurrentUserProfile.Username); Video.Views += 1; await storageService.Save(Video.Id, Video); return(Page()); }