Exemplo n.º 1
0
        public async Task <ActionResult> Create([Bind("Text")] NewTweetViewModel newTweet)
        {
            if (ModelState.IsValid)
            {
                var tweet = new Tweet
                {
                    Id        = Guid.NewGuid(),
                    Author    = _userManager.GetUserName(User),
                    Text      = newTweet.Text,
                    Timestamp = DateTime.UtcNow
                };
                await _repository.CreateTweetAsync(tweet);

                await _queue.EnqueueNotificationAsync(tweet);

                return(RedirectToAction("Index"));
            }

            return(View(newTweet));
        }
        public async Task CreateTweetAsync(ClaimsPrincipal user, NewTweetViewModel tweetViewModel)
        {
            var tweetId = Guid.NewGuid();

            var imageUrl = null != tweetViewModel.Image
                ? await UploadImage(tweetId.ToString(), tweetViewModel.Image)
                : string.Empty;

            var tweet = new Tweet
            {
                Id        = tweetId,
                Author    = _userManager.GetUserName(user),
                Text      = tweetViewModel?.Text ?? string.Empty,
                Timestamp = DateTime.UtcNow,
                ImageUri  = imageUrl
            };

            await _tweetsRepository.CreateTweetAsync(tweet);

            await _queue.EnqueueNotificationAsync(tweet);
        }