예제 #1
0
        public DeletePostResponse SendDeletePostRequest(DeletePostRequest request)
        {
            DeletePostResponse response = new DeletePostResponse();

            var rpcClient  = new XmlRpcRestClient(config.RequestUrl);
            var rpcRequest = new XmlRpcRestRequest(request.RequestUrl)
            {
                Method = Method.POST
            };

            // Add request parameters
            rpcRequest.AddXmlRpcBody(config.BlogID, config.Username, config.Password, request.PostId);

            try
            {
                // Get response
                var rpcResponse = rpcClient.Execute <RpcResponseValue <string> >(rpcRequest);

                // Find and fill members in
                response.Success = rpcResponse.Data.Value != "false";
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }

            return(response);
        }
예제 #2
0
        public override Task <DeletePostResponse> DeletePost(DeletePostRequest request, ServerCallContext context)
        {
            DeletePostResponse output = new DeletePostResponse();

            _context.Remove(request.Id);
            _context.SaveChanges();
            return(Task.FromResult(output));
        }
예제 #3
0
        public DeletePostResponse Handle(DeletePost command)
        {
            var response = new DeletePostResponse();

            try
            {
                var user = _membershipService.GetUserById(command.DeleteBy);

                if (user == null)
                {
                    response.Error = "Invalid user.";
                    return(response);
                }

                var post = _postService.GetPostById(command.PostId);

                if (post == null)
                {
                    response.Error = "Invalid post.";
                    return(response);
                }

                if (post.UserId == user.Id || user.IsAdmin)
                {
                    post.Deleted = true;
                    _postService.UpdatePost(post);

                    // let's remove the single vote that the author may have attributed to this post.
                    // this will prevent people from creating/deleting post for a single kudo, over and over.
                    _commandBus.Send(new CastVoteForPost
                    {
                        VoteType   = null, // unvote the comment!
                        PostId     = post.Id,
                        DateCasted = Common.CurrentTime(),
                        IpAddress  = string.Empty, // TODO,
                        UserId     = post.UserId
                    });
                }
                else
                {
                    response.Error = "You cannot delete this post.";
                    return(response);
                }

                return(response);
            }
            catch (Exception ex)
            {
                _logger.Error("Error editing post.", ex);
                response.Error = "An unknown error occured.";
                return(response);
            }
        }
예제 #4
0
 public override Task <DeletePostResponse> DeletePost(DeletePostRequest request, ServerCallContext context)
 {
     try
     {
         var post        = new PostComment.Post();
         var returnValue = post.DeletePost(request.Id);
         var response    = new DeletePostResponse {
             Value = returnValue
         };
         return(Task.FromResult(response));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "Error invoking DeletePost");
         throw new RpcException(new Status(StatusCode.Internal, ex.Message));
     }
 }
예제 #5
0
        public Task <bool> DeletePostByPostId(long postId, CancellationTokenSource cancellationTokenSource) =>
        Task <bool> .Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            bool completionResult = false;

            DeletePostRequest deletePostRequest = new DeletePostRequest()
            {
                Url         = string.Format(GlobalSettings.Instance.Endpoints.PostEndpoints.DeletePostByPostIdEndPoint, postId),
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken
            };

            try {
                DeletePostResponse deletePostResponse = await _requestProvider.PostAsync <DeletePostRequest, DeletePostResponse>(deletePostRequest);

                if (deletePostResponse != null)
                {
                    completionResult = true;
                }
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (Exception exc) {
                Crashes.TrackError(exc);

                Debug.WriteLine($"ERROR:{exc.Message}");
                throw;
            }

            return(completionResult);
        }, cancellationTokenSource.Token);