コード例 #1
0
        public ActionResult <TweetResponseDto> DeleteTweet(CredentialsDto credentials, int id)
        {
            var result       = _tweetService.DeleteTweet(credentials, id);
            var mappedTweets = _mapper.Map <Tweet, TweetResponseDto>(result);

            return(mappedTweets);
        }
コード例 #2
0
        public ActionResult <TweetDto> DeleteTweet(int id, [FromBody] CredentialsDto credentialsDto)
        {
            var credentials  = _mapper.Map <Credentials>(credentialsDto);
            var user         = _userService.GetAndValidateUser(credentials);
            var deletedTweet = _tweetService.DeleteTweet(id, user);

            return(_mapper.Map <TweetDto>(deletedTweet));
        }
コード例 #3
0
        public async Task <IActionResult> Delete([FromBody] TweetViewModel model)
        {
            var userId = this.userManager.GetUserId(this.HttpContext.User);
            var deletedSuccessfully = await tweetService.DeleteTweet(userId, model.Id);

            if (deletedSuccessfully)
            {
                return(Json("Tweet successfully deleted!"));
            }

            return(Json("Tweet could not be deleted!"));
        }
コード例 #4
0
        public IActionResult DeleteTweet(int id, int loggedInUserId)
        {
            var tweet     = _tweetService.GetTweetById(id);
            var belongsTo = tweet.UserId;

            if (belongsTo == loggedInUserId)
            {
                _tweetService.DeleteTweet(id);
            }
            //return success or error message
            return(Ok(id));
        }
コード例 #5
0
ファイル: TweetController.cs プロジェクト: ramonaerts/Kwetter
        public async Task <ApiResult> DeleteTweet(string id)
        {
            try
            {
                var userId     = User.Claims.First(c => c.Type == ClaimTypes.Name).Value.ToString();
                var roleString = User.Claims.First(c => c.Type == ClaimTypes.Role).Value.ToString();

                var result = await _tweetService.DeleteTweet(id, userId, roleString);

                return(result ? ApiResult.Success("Tweet deleted") : ApiResult.NotFound("Something went wrong"));
            }
            catch (Exception)
            {
                return(ApiResult.BadRequest("Something went wrong"));
            }
        }
コード例 #6
0
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            _logger.LogInformation("Getting Tweet ({ID})", id.Value);
            var tweetToDelete = await _tweetService.GetTweetForDeletion(id.Value);

            if (tweetToDelete == null)
            {
                _logger.LogWarning("Tweet ({ID}) NOT FOUND", id.Value);
                Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                return(Json(new { Message = "Requested Tweet was not found" }));
            }

            _logger.LogInformation("Deleting Tweet ({ID})", id.Value);
            await _tweetService.DeleteTweet(tweetToDelete);

            return(Json(new { Message = "Tweet deleted successfully" }));
        }
コード例 #7
0
        public void shouldDeleteTweet(string tweetId)
        {
            var result = _tweetService.DeleteTweet(tweetId);

            Assert.IsTrue(result);
        }