/// <summary> /// 删除评论 /// </summary> /// <param name="cid">评论ID</param> /// <returns></returns> public JsonResult DeleteComments(string fid, string cid) { bool result = false; try { var client1 = new JsonServiceClient(http + "/SNSApi/"); DeleteComment comment = new DeleteComment { FId = new Guid(fid), CID = cid }; client1.Delete(comment); result = true; } catch (Exception) { throw; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public void TestDeleteCommentWorksWithExistingComment() { int commentId = 1; DeleteComment delComment = new DeleteComment(); Assert.IsTrue(delComment.GetCommand(commentId)); }
private static Response DeleteCommentResponse(DeleteComment deleteComment) { Acknowledge ack = new Acknowledge() { Status = "OK", Reason = "" }; Response resp = new Response() { Type = ResponseType.Acknowledge, Status = "OK", Content = ack }; string query = string.Format("DELETE FROM comments WHERE uid = '{0}' AND videoid = '{1}'", deleteComment.CommentID, deleteComment.VideoID); DatabaseManager database = new DatabaseManager(); (MySqlDataReader reader, var Connection) = database.RunQuery(query); if (reader != null) { if (reader.RecordsAffected == 0) { ack.Status = "FAIL"; ack.Reason = "Failed to delete comment."; } Connection.Close(); return(resp); } else { Connection.Close(); return(new Response() { Type = ResponseType.Acknowledge, Status = "FAIL" }); } }
public async Task <IActionResult> DeleteComment([FromBody] DeleteComment model) { var callerId = await _authHelper.GetCallerId(_caller); if (await _authHelper.CheckIfUserIsBanned(callerId)) { return(new BadRequestObjectResult( new { Message = "User currently bannend", StatusCodes.Status403Forbidden })); } var result = await _commentRepository.DeleteComment(model.CommentId, callerId); if (result.Successfull) { if (result.RemainingFiles.Any()) { _uploadHelper.DeleteCommentFiles(result.RemainingFiles); } return(new OkObjectResult(new { result })); } return(new BadRequestObjectResult( new { result, StatusCodes.Status403Forbidden })); }
public async Task <IActionResult> DeleteSubComment(int newsId, int commentId, [FromServices] DeleteComment deleteComment) { await deleteComment.DeleteSubComment(commentId); return(RedirectToAction("SingleNewsDisplay", new { id = newsId })); }
public async Task <IActionResult> DeleteComment(int groupId, int postId, int commentId) { var command = new DeleteComment { GroupId = groupId, PostId = postId, CommentId = commentId }; return(Ok(await _mediator.Send(command))); }
public static d.CommentEntity ToDal(this DeleteComment comment) { return(new d.CommentEntity() { Id = comment.Id, Reason = comment.Reason }); }
public async Task <IActionResult> DeleteComment(string app, DomainId commentsId, DomainId commentId) { var command = new DeleteComment { CommentsId = commentsId, CommentId = commentId }; await CommandBus.PublishAsync(command); return(NoContent()); }
public static void CanDelete(List <Envelope <CommentsEvent> > events, DeleteComment command) { Guard.NotNull(command); var comment = FindComment(events, command.CommentId); if (!comment.Payload.Actor.Equals(command.Actor)) { throw new DomainException("Comment is created by another actor."); } }
public void CanDelete_should_throw_exception_if_comment_not_found() { var commentId = DomainId.NewGuid(); var command = new DeleteComment { CommentId = commentId, Actor = user1 }; var events = new List <Envelope <CommentsEvent> >(); Assert.Throws <DomainObjectNotFoundException>(() => GuardComments.CanDelete(commentsId, events, command)); }
public static void CanDelete(DeleteComment command, string commentsId, List <Envelope <CommentsEvent> > events) { Guard.NotNull(command, nameof(command)); var comment = FindComment(events, command.CommentId); if (!string.Equals(commentsId, command.Actor.Identifier) && !comment.Payload.Actor.Equals(command.Actor)) { throw new DomainException(T.Get("comments.notUserComment")); } }
public async Task Handle_Success() { // Arrange var request = new DeleteComment(validCommentId); // Act var result = await interactor.Handle(request, CancellationToken.None); // Assert result.IsSuccessful.Should().BeTrue(); A.CallTo(() => repository.DeleteAsync(A <Comment> ._)) .MustHaveHappenedOnceExactly(); }
public async Task Handle_NotFound() { // Arrange var request = new DeleteComment(new Guid("3BE6DCBE-D46D-472D-890E-FE99700830EB")); // Act var result = await interactor.Handle(request, CancellationToken.None); // Assert result.IsSuccessful.Should().BeFalse(); result.ResultCategory.Should().Be(ResultCategory.NotFound); A.CallTo(() => repository.DeleteAsync(A <Comment> ._)) .MustNotHaveHappened(); }
public async Task <IActionResult> DeleteComment(DomainId userId, DomainId commentId) { CheckPermissions(userId); var commmand = new DeleteComment { AppId = NoApp, CommentsId = userId, CommentId = commentId }; await CommandBus.PublishAsync(commmand); return(NoContent()); }
public async Task <object> Delete(DeleteComment request) { try { await _commentsRepository.DeleteCommentAsync(request.Id); return(new DeleteCommentResponse()); } catch (Exception ex) { return(new DeleteCommentResponse { ResponseStatus = GetResponseStatus(ex) }); } }
public void CanDelete_should_not_throw_exception_if_comment_from_same_user() { var commentId = DomainId.NewGuid(); var command = new DeleteComment { CommentId = commentId, Actor = user1 }; var events = new List <Envelope <CommentsEvent> > { Envelope.Create <CommentsEvent>(new CommentCreated { CommentId = commentId, Actor = user1 }).To <CommentsEvent>() }; GuardComments.CanDelete(commentsId, events, command); }
public void CanDelete_should_throw_exception_if_comment_from_another_user() { var commentId = DomainId.NewGuid(); var command = new DeleteComment { CommentId = commentId, Actor = user2 }; var events = new List <Envelope <CommentsEvent> > { Envelope.Create <CommentsEvent>(new CommentCreated { CommentId = commentId, Actor = user1 }).To <CommentsEvent>() }; Assert.Throws <DomainException>(() => GuardComments.CanDelete(commentsId, events, command)); }
public void CanDelete_should_not_throw_exception_if_comment_is_own_notification() { var commentId = DomainId.NewGuid(); var command = new DeleteComment { CommentId = commentId, Actor = user1 }; var events = new List <Envelope <CommentsEvent> > { Envelope.Create <CommentsEvent>(new CommentCreated { CommentId = commentId, Actor = user1 }).To <CommentsEvent>() }; GuardComments.CanDelete(command, user1.Identifier, events); }
public async Task Delete_should_create_events_and_update_state() { var createCommand = new CreateComment { Text = "text1" }; var updateCommand = new UpdateComment { Text = "text2", CommentId = createCommand.CommentId }; var deleteCommand = new DeleteComment { CommentId = createCommand.CommentId }; await sut.ExecuteAsync(CreateCommentsCommand(createCommand)); await sut.ExecuteAsync(CreateCommentsCommand(updateCommand)); var result = await sut.ExecuteAsync(CreateCommentsCommand(deleteCommand)); result.ShouldBeEquivalent(new EntitySavedResult(2)); sut.GetCommentsAsync(-1).Result.Should().BeEquivalentTo(new CommentsResult { Version = 2 }); sut.GetCommentsAsync(0).Result.Should().BeEquivalentTo(new CommentsResult { DeletedComments = new List <Guid> { deleteCommand.CommentId }, Version = 2 }); sut.GetCommentsAsync(1).Result.Should().BeEquivalentTo(new CommentsResult { DeletedComments = new List <Guid> { deleteCommand.CommentId }, Version = 2 }); LastEvents .ShouldHaveSameEvents( CreateCommentsEvent(new CommentDeleted { CommentId = createCommand.CommentId }) ); }
public void CanDelete_should_throw_exception_if_comment_deleted() { var commentId = DomainId.NewGuid(); var command = new DeleteComment { CommentId = commentId, Actor = user1 }; var events = new List <Envelope <CommentsEvent> > { Envelope.Create <CommentsEvent>(new CommentCreated { CommentId = commentId, Actor = user1 }), Envelope.Create <CommentsEvent>(new CommentDeleted { CommentId = commentId }) }; Assert.Throws <DomainObjectNotFoundException>(() => GuardComments.CanDelete(command, commentsId, events)); }
private async void deleteButton_Click(object sender, RoutedEventArgs e) { DeleteComment comment = new DeleteComment() { VideoID = Comment.VideoID, CommentID = (string)Tag, UserID = Comment.UserId }; deleteCommentProgressRing.isActive = true; Object resp = new JObject(); resp = await ConnectionManager.SendRequestAsync(comment, RequestType.DeleteComment, ResponseType.Acknowledge); if (resp != null) { Acknowledge ack = ((JObject)resp).ToObject <Acknowledge>(); if (ack.Status == "OK") { Visibility = Visibility.Collapsed; } } deleteCommentProgressRing.isActive = false; }
public async Task Delete_should_create_events() { await ExecuteCreateAsync(); await ExecuteUpdateAsync(); var deleteCommand = new DeleteComment(); var result = await sut.ExecuteAsync(CreateCommentsCommand(deleteCommand)); result.ShouldBeEquivalent((object)new EntitySavedResult(2)); sut.GetCommentsAsync(-1).Result.Should().BeEquivalentTo(new CommentsResult { Version = 2 }); sut.GetCommentsAsync(0).Result.Should().BeEquivalentTo(new CommentsResult { DeletedComments = new List <Guid> { commentId }, Version = 2 }); sut.GetCommentsAsync(1).Result.Should().BeEquivalentTo(new CommentsResult { DeletedComments = new List <Guid> { commentId }, Version = 2 }); LastEvents .ShouldHaveSameEvents( CreateCommentsEvent(new CommentDeleted()) ); }
public async Task <IActionResult> DeleteComment([FromBody] DeleteComment command) { await DispatchAsync(command); return(NoContent()); }
private void MenuItemDeleteComment_OnClick(object sender, RoutedEventArgs e) { CommonMethods.WorkWithTables.Delete(thisComment, httpClientProvider.GetDatabaseCommentEditor(), comment => comment.CommentId, () => DeleteComment?.Invoke(this, default(EventArgs))); }
public void Delete(DeleteComment command) { RaiseEvent(SimpleMapper.Map(command, new CommentDeleted())); }
public DeleteCommentResponse Handle(DeleteComment command) { var response = new DeleteCommentResponse(); try { var comment = _commentService.GetCommentById(command.CommentId); if (comment == null) { response.Error = "Invalid comment."; return(response); } if (comment.Deleted) { // don't return error, just return success, because it was already deleted. return(response); } var user = _membershipService.GetUserByUserName(command.UserName); if (user == null) { response.Error = "Invalid user."; return(response); } if (!_permissionService.CanUserDeleteComment(user, comment)) { response.Error = "You are not allowed to delete this comment."; return(response); } string newBody; if (user.Id == comment.AuthorUserId) { newBody = "deleted by author on " + command.DateDeleted.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'"); } else if (user.IsAdmin) { newBody = "deleted by admin on " + command.DateDeleted.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'"); } else if (_permissionService.CanUserManageSubPosts(user, comment.SubId)) { newBody = "deleted by mod on " + command.DateDeleted.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'"); } else { newBody = "deleted on " + command.DateDeleted.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'"); } _commentService.DeleteComment(comment.Id, newBody); _eventBus.Publish(new CommentDeleted { CommentId = comment.Id, PostId = comment.PostId, SubId = comment.SubId, DeletedByUserId = user.Id }); // let's remove the single vote that the author may have attributed to this comment. // this will prevent people from creating/deleting comments for a single kudo, over and over. _commandBus.Send(new CastVoteForComment { VoteType = null, // unvote the comment! CommentId = comment.Id, DateCasted = Common.CurrentTime(), IpAddress = string.Empty, // TODO, UserId = comment.AuthorUserId }); } catch (Exception ex) { response.Error = ex.Message; } return(response); }
public void Handle(DeleteComment request) { var msg = new CommentDeleted(request.CommentId); Send(msg); }
public static void CanDelete(string commentsId, List <Envelope <CommentsEvent> > events, DeleteComment command) { Guard.NotNull(command, nameof(command)); var comment = FindComment(events, command.CommentId); if (!string.Equals(commentsId, command.Actor.Identifier) && !comment.Payload.Actor.Equals(command.Actor)) { throw new DomainException("Comment is created by another user."); } }
public void Delete(Guid id) { var request = new DeleteComment(id); _handler.Handle(request); }
public IActionResult Delete(DeleteComment comment) { _repoCmt.Delete(comment.ToDal()); return(Ok()); }