Beispiel #1
0
        /// <summary>
        ///     Called when a vlog has been uploaded. This will
        ///     publish the vlog and notify all followers.
        /// </summary>
        /// <remarks>
        ///     <para>
        ///         The vlog will be owned by the current user.
        ///     </para>
        ///     <para>
        ///         If the video file or thumbnail file does not
        ///         exist in our blob storage this throws a
        ///         <see cref="FileNotFoundException"/>.
        ///     </para>
        /// </remarks>
        /// <param name="context">Context for posting the vlog.</param>
        public async Task PostVlogAsync(PostVlogContext context)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (!await _blobStorageService.FileExistsAsync(StorageConstants.VlogStorageFolderName, StorageHelper.GetVideoFileName(context.VlogId)))
            {
                throw new FileNotFoundException();
            }
            if (!await _blobStorageService.FileExistsAsync(StorageConstants.VlogStorageFolderName, StorageHelper.GetThumbnailFileName(context.VlogId)))
            {
                throw new FileNotFoundException();
            }

            var vlog = new Vlog
            {
                Id        = context.VlogId,
                IsPrivate = context.IsPrivate,
                UserId    = context.UserId,
            };

            await _vlogRepository.CreateAsync(vlog);

            // TODO AppContext.UserId returned Guid.Empty. Why? --> context.UserId will work.
            // This function will dispatch a notification for each follower.
            await _notificationService.NotifyFollowersVlogPostedAsync(context.UserId, context.VlogId);
        }
Beispiel #2
0
        public IActionResult PostVlog([FromServices] DispatchManager dispatchManager, [FromServices] Core.AppContext appContext, [FromBody] VlogDto input)
        {
            // Act.
            var postVlogContext = new PostVlogContext
            {
                IsPrivate = input.IsPrivate,
                UserId    = appContext.UserId,
                VlogId    = input.Id,
            };

            dispatchManager.Dispatch <PostVlogBackgroundTask>(postVlogContext);

            // Return.
            return(NoContent());
        }