public async Task <JsonNetResult> Add(AddCommentViewModel model) { // Shouldn't throw because of the Authorize attribute Guid userId = User.GetCurrentUserId().Value; var commentTimestamp = DateTimeOffset.UtcNow; // Add the new comment var commentOnVideo = new CommentOnVideo { UserId = userId, VideoId = model.VideoId, CommentId = TimeUuid.NewId(commentTimestamp), Comment = model.Comment }; await _comments.CommentOnVideo(commentOnVideo); // Lookup the current user's information to include in the return data UserProfile userInfo = await _userManagement.GetUserProfile(userId); return(JsonSuccess(new VideoCommentViewModel { CommentId = commentOnVideo.CommentId, Comment = commentOnVideo.Comment, CommentTimestamp = commentTimestamp, UserProfileUrl = Url.Action("Info", "Account", new { userId }), UserFirstName = userInfo.FirstName, UserLastName = userInfo.LastName, UserGravatarImageUrl = GravatarHasher.GetImageUrlForEmailAddress(userInfo.EmailAddress) })); }
public async Task Handle(AddSampleComments busCommand) { // Get some sample users to use as comment authors List <Guid> userIds = await _sampleDataRetriever.GetRandomSampleUserIds(busCommand.NumberOfComments).ConfigureAwait(false); if (userIds.Count == 0) { Logger.Warn("No sample users available. Cannot add sample comments."); return; } // Get some videos to comment on List <Guid> videoIds = await _sampleDataRetriever.GetRandomVideoIds(busCommand.NumberOfComments).ConfigureAwait(false); if (videoIds.Count == 0) { Logger.Warn("No sample videos available. Cannot add sample comments."); return; } // Choose a NLipsum generator for generating the comment text int lipsumIdx = new Random().Next(LipsumSources.Length); var lipsum = new LipsumGenerator(LipsumSources[lipsumIdx](), false); var comments = lipsum.GenerateParagraphs(busCommand.NumberOfComments, Paragraph.Short); // Add some sample comments in parallel var commentTasks = new List <Task>(); for (int i = 0; i < busCommand.NumberOfComments; i++) { commentTasks.Add(_commentService.CommentOnVideo(new CommentOnVideo { CommentId = TimeUuid.NewId(), VideoId = videoIds[i], UserId = userIds[i], Comment = comments[i] })); } await Task.WhenAll(commentTasks).ConfigureAwait(false); }