private async void PostCommentButton_Tapped(object sender, TappedRoutedEventArgs e) { string body; CommentTextBox.Document.GetText(Windows.UI.Text.TextGetOptions.None, out body); if (!AuthenticationService.IsLogin) { MessageDialog messageDialog = new MessageDialog("请先登录"); await messageDialog.ShowAsync(); AuthenticationService.RedictLoginPage(); return; } PostBlogComment postBlogComment = new PostBlogComment(); postBlogComment.BlogApp = this.BlogCommentViewModel.Blog.BlogApp; postBlogComment.Body = body; postBlogComment.ParentCommentId = "0"; postBlogComment.PostId = this.BlogCommentViewModel.Blog.Id; PostResult postBlogCommentResponse = await BlogService.PostCommentAsync(postBlogComment); if (!postBlogCommentResponse.IsSuccess) { MessageDialog messageDialog = new MessageDialog(postBlogCommentResponse.Message); await messageDialog.ShowAsync(); //其他异常则不处理 if (postBlogCommentResponse.Message.Contains("登录")) { AuthenticationService.RedictLoginPage(); } return; } else { //TODO:使用API,评论不会马上刷出来,需要改成http获取进行解析才可以实时显示最新评论 //{ "Id":0,"IsSuccess":false,"Message":"请先登录!","Data":null} this.BlogCommentViewModel.Refresh(); } }
public static async Task <PostResult> PostCommentAsync(PostBlogComment postBlogComment) { try { string data = JsonSerializeHelper.Serialize(postBlogComment); string json = await HttpHelper.Post(WcfApiUrlConstants.PostBlogComment, data, CacheManager.LoginUserInfo.Cookies); PostResult response = JsonSerializeHelper.Deserialize <PostResult>(json); return(response); } catch (Exception exception) { System.Diagnostics.Debug.WriteLine(exception.Message); return(new PostResult() { IsSuccess = false, Message = "提交时发送异常" }); } }
public static async Task<PostResult> PostCommentAsync(PostBlogComment postBlogComment) { try { string data = JsonSerializeHelper.Serialize(postBlogComment); string json = await HttpHelper.Post(WcfApiUrlConstants.PostBlogComment, data, CacheManager.LoginUserInfo.Cookies); PostResult response = JsonSerializeHelper.Deserialize<PostResult>(json); return response; } catch (Exception exception) { System.Diagnostics.Debug.WriteLine(exception.Message); return new PostResult() { IsSuccess = false, Message = "提交时发送异常" }; } }