Пример #1
0
 public IActionResult AddTweet([FromBody] Tweet tweet)
 {
     if (tweet.Content.Trim() != "")
     {
         _tweetService.AddTweet(tweet);
     }
     //return success or error message
     return(Ok());
 }
Пример #2
0
        public async Task <IActionResult> AddTweet(AddTweetDTO model)
        {
            if (ModelState.IsValid)
            {
                if (model.AppUserId == User.GetUserId())
                {
                    await _tweetServices.AddTweet(model);

                    return(Json("Success"));
                }
                else
                {
                    return(Json("Failed"));
                }
            }
            else
            {
                return(BadRequest(String.Join(Environment.NewLine, ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage + "" + x.Exception))));
            }
        }
Пример #3
0
        /// <summary>
        /// Inserts new tweet to the database
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _logger.LogInformation("Getting authenticated User");
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                _logger.LogWarning("User NOT FOUND");
                return(NotFound());
            }

            _logger.LogInformation("Inserting new Tweet entity with text ({TEXT}) and User Id ({ID})", Tweet.Text, user.Id);
            await _tweetService.AddTweet(Tweet.Text, user);

            return(RedirectToPage());
        }