protected void Unpublish_Click(object sender, EventArgs e) // Unpublish an approved comment
 {
     MessageBox.Show(((LinkButton)sender).CommandArgument);
     using (Service1Client client = new Service1Client())
     {
         PublishCommentResponse response = client.PublishComment(new PublishCommentRequest()
         {
             _id         = ((LinkButton)sender).CommandArgument,
             IsPublished = false
         });
         if (!response.Errored)
         {
             Response.Redirect("~/Comments");
         }
     }
 }
Exemplo n.º 2
0
        public async Task <CommentDTO> PublishCommentAsync(PublishCommentDataModel publishCommentDataModel, CancellationToken cancellationToken) =>
        await Task.Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            PublishCommentRequest publishCommentRequest = new PublishCommentRequest {
                Url         = GlobalSettings.Instance.Endpoints.PostEndpoints.PublishCommentEndPoint,
                Data        = publishCommentDataModel,
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken
            };

            PublishCommentResponse publishCommentResponse = null;
            CommentDTO commentResult = null;

            try {
                publishCommentResponse =
                    await _requestProvider.PostAsync <PublishCommentRequest, PublishCommentResponse>(publishCommentRequest);

                if (publishCommentResponse != null)
                {
                    commentResult = new CommentDTO()
                    {
                        Author       = publishCommentResponse.Author,
                        CreationTime = publishCommentResponse.CreationTime,
                        Id           = publishCommentResponse.Id,
                        Text         = publishCommentResponse.Text
                    };
                }
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

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

                Debug.WriteLine($"ERROR:{ex.Message}");
                throw new Exception(ex.Message);
            }

            return(commentResult);
        }, cancellationToken);