public async Task <IActionResult> RemoveAsync(Guid id) { RemovePostCommand command = new RemovePostCommand { PostId = id }; return(await CreateCommandResponse(command)); }
public async Task <CommandResult> Handle(RemovePostCommand request, CancellationToken cancellationToken) { Post post = await _postRepository.GetByIdAsync(request.PostId); if (post == null || post.ProfileId != _currentProfileId) { return(FailureDueToPostNotFound()); } await _postRepository.RemoveAsync(post); return(await CommitAndPublishDefaultAsync()); }
public async Task <IActionResult> RemovePost(long postId) { var query = new RemovePostCommand(postId); var result = await _mediator.Send(query); switch (result) { case ResultStatus.NotFound: return(Error(new { info = "کاربری یافت نشد." })); case ResultStatus.Success: return(Success()); default: return(Error(new { info = "خطایی رخ داده است" })); } }
/// <summary> /// Deletes a post /// </summary> /// <param name="postId">the id of the post to delete</param> /// <returns>true/false, true if successfully deleted, false otherwise</returns> public JsonResult DeletePost(int postId) { //Queries for the current user and their email address. - Chris SelectUserQuery currentUser = new SelectUserQuery(new CurrentUser(claimsHelper.GetUserNameFromClaim((ClaimsIdentity)User.Identity))); CurrentUser user = commandBus.ProcessQuery(currentUser); GetPostByPostIdQuery query = new GetPostByPostIdQuery(postId); Post newPost = commandBus.ProcessQuery(query); if (newPost.PostStatus == Convert.ToInt32(PostStatusEnum.Delivered.Id) || newPost.PostStatus == Convert.ToInt32(PostStatusEnum.PendingDelivery.Id)) { return(Json("false", JsonRequestBehavior.AllowGet)); } RemovePostCommand command = new RemovePostCommand(new Post(postId), user.LoginName); commandBus.Execute(command); return(Json("true", JsonRequestBehavior.AllowGet)); }
public void Handle(RemovePostCommand message) { var currentPost = _topicRepository.GetPost(message.Id); if (currentPost == null) { return; } if (currentPost.UserId != _user.GetUserId()) { currentPost.ValidationResult.Errors.Add(new ValidationFailure("UserId", "Acesso negado.")); NotifyErrors(currentPost.ValidationResult); return; } currentPost.SetRemoved(); _topicRepository.UpdatePost(currentPost); if (Commit()) { _bus.RaiseEvent(new RemovedPostEvent(message.Id)); } }
/// <summary> /// Handler for the RemovePostCommand command /// </summary> /// <param name="command">the RemovePost Command</param> public void HandleCommand(RemovePostCommand command) { postRepository.RemovePost(command.Post, command.UserName); }