/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { DeleteCommentResponse response = new DeleteCommentResponse(); return(response); }
//TODO: Delete a comment protected void DeleteComment_Click(object sender, EventArgs e) { using (Service1Client client = new Service1Client()) { DeleteCommentResponse response = client.DeleteComment(new DeleteCommentRequest() { _id = ((LinkButton)sender).CommandArgument, }); if (response.Errored) { Response.Redirect("~/Comments"); } else { Response.Redirect("~/Comments"); } } }
public async Task <DeleteCommentResponse> DeleteComment(int commentId, string callerId) { var deleteCommentQuery = $@" DELETE FROM juniro.comments WHERE Id=@commentId AND UserId = @callerId;"; var deleteCommentFileQuery = $@" DELETE FROM juniro.comment_files WHERE CommentId=@commentId;"; var toBeDeletedCommentFiles = $@" SELECT * FROM juniro.comment_files WHERE CommentId=@commentId"; var result = new DeleteCommentResponse() { Message = "You cannot delete this comment.", Successfull = false, RemainingFiles = new List <CommentFiles>() }; using (var connection = new MySqlConnection(_connectionString)) { var affectedRows = await connection.ExecuteAsync(deleteCommentQuery, new { commentId, callerId }); if (affectedRows <= 0) { return(result); } var files = await connection.QueryAsync <CommentFiles>(toBeDeletedCommentFiles, new { commentId }); await connection.ExecuteAsync(deleteCommentFileQuery, new { commentId }); result.RemainingFiles = files.AsList(); result.Message = "Comment successfully deleted."; result.Successfull = true; } return(result); }
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); }