public ActionResult <TweetResponseDto> DeleteTweet(CredentialsDto credentials, int id) { var result = _tweetService.DeleteTweet(credentials, id); var mappedTweets = _mapper.Map <Tweet, TweetResponseDto>(result); return(mappedTweets); }
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)); }
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!")); }
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)); }
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")); } }
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" })); }
public void shouldDeleteTweet(string tweetId) { var result = _tweetService.DeleteTweet(tweetId); Assert.IsTrue(result); }