示例#1
0
        public async Task <IActionResult> Create(ChannelCreation channelCreation)
        {
            AppUser currentUser = await _userManager.GetUserAsync(User);

            if (currentUser.IsCreatingChannel)
            {
                ModelState.AddModelError(string.Empty, "User is already creating a channel.");
            }
            else if (ModelState.IsValid)
            {
                currentUser.IsCreatingChannel = true;
                await _userManager.UpdateAsync(currentUser);

                if (await _youTubeService.IsValidUrl(channelCreation.StartingMedia))
                {
                    _channelTaskLoader.Enqueue(new ChannelCreationTask(channelCreation, DateTime.Now, currentUser.Id));

                    return(NoContent());
                }

                currentUser.IsCreatingChannel = false;
                await _userManager.UpdateAsync(currentUser);

                ModelState.AddModelError(nameof(channelCreation.StartingMedia), StartingMediaValidationMessage);
            }

            return(BadRequest(ModelState));
        }