private async void btnPublishComment_Click(object sender, RoutedEventArgs e)
 {
     //发表评论
     try
     {
         if (string.IsNullOrEmpty(txtComment.Text))
         {
             throw new Exception("评论不能为空");
         }
         txtComment.IsEnabled        = false;
         btnPublishComment.IsEnabled = false;
         btnNewComment.IsEnabled     = false;
         var res = await new PixivAppAPI(Data.OverAll.GlobalBaseAPI)
                   .IllustCommentAdd(illustID.ToString(), txtComment.Text);
         Data.IllustCommentItem      newItem   = Data.IllustCommentItem.FromJsonValue(res["comment"].GetObject());
         ViewModels.CommentViewModel viewModel = ViewModels.CommentViewModel.FromItem(newItem);
         _ = viewModel.LoadAvatarAsync();
         (listComments.ItemsSource as CommentsCollection).Insert(0, viewModel);
         (((FrameworkElement)Frame?.Parent)?.Parent as MainPage)
         ?.ShowTip("评论已发表");
     }
     catch (Exception exception)
     {
         (((FrameworkElement)Frame?.Parent)?.Parent as MainPage)
         ?.ShowTip(string.Format("评论未能发表:{0}", exception.Message));
     }
     finally
     {
         btnNewComment.IsChecked     = false;
         txtComment.IsEnabled        = true;
         btnPublishComment.IsEnabled = true;
         btnNewComment.IsEnabled     = true;
         txtComment.Text             = "";
     }
 }
        public static IllustCommentItem FromJsonValue(JsonObject Source)
        {
            IllustCommentItem toret = new IllustCommentItem();

            toret.ID          = (int)Source["id"].GetNumber();
            toret.Comment     = Source["comment"].TryGetString();
            toret.DateTime    = Source["date"].TryGetString();
            toret.UserName    = Source["user"].GetObject()["name"].TryGetString();
            toret.UserAccount = Source["user"].GetObject()["account"].TryGetString();
            toret.AvatarUrl   = Source["user"].GetObject()["profile_image_urls"].GetObject()["medium"].TryGetString();
            string parent;

            try
            {
                parent = Source["parent_comment"].ToString();
            }
            catch
            {
                parent = "{}";
            }
            if (parent != "{}")
            {
                //有父级评论
                toret.ParentCommentID = (int)Source["parent_comment"].GetObject()["id"].GetNumber();
            }
            else
            {
                toret.ParentCommentID = -1;
            }
            return(toret);
        }
        public static IllustCommentItem FromJsonValue(JsonObject Source)
        {
            IllustCommentItem toret = new IllustCommentItem();

            toret.Comment     = Source["comment"].TryGetString();
            toret.DateTime    = Source["date"].TryGetString();
            toret.UserName    = Source["user"].GetObject()["name"].TryGetString();
            toret.UserAccount = Source["user"].GetObject()["account"].TryGetString();
            toret.AvatarUrl   = Source["user"].GetObject()["profile_image_urls"].GetObject()["medium"].TryGetString();
            return(toret);
        }
示例#4
0
        public static IllustCommentItem FromObject(PixivCS.Objects.Comment Source)
        {
            IllustCommentItem toret = new IllustCommentItem();

            toret.ID          = (int)Source.Id;
            toret.Comment     = Source.CommentComment;
            toret.DateTime    = Source.Date;
            toret.UserName    = Source.User.Name;
            toret.UserAccount = Source.User.Account;
            toret.AvatarUrl   = Source.User.ProfileImageUrls.Medium?.ToString() ?? "";
            if (Source.ParentComment.CommentComment != null)
            {
                //有父级评论
                toret.ParentCommentID = (int)Source.ParentComment.Id;
            }
            else
            {
                toret.ParentCommentID = -1;
            }
            return(toret);
        }