コード例 #1
0
        /// <summary>
        /// Fires when the user intends to delete his or her post.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            string tokenBuild = "Bearer " + Token;
            Button btn        = sender as Button;

            ForumModel.Datum datum = (ForumModel.Datum)btn.DataContext;

            if (datum != null)
            {
                int id = datum.id;

                string endpoint = @"https://api.africoders.com/v1/del/post?id=" + id.ToString();

                postHelper            = new PostHelper(endpoint);
                loadingTextBlock.Text = "Deleting Post.";
                await postHelper.MakePostAsync(tokenBuild);

                if (postHelper.StatusPostSuccessful)
                {
                    loadingTextBlock.Text = "Deleted Post Successfully.";
                    Refresh();
                }
                else
                {
                    loadingTextBlock.Text = "Unable to delete post. Please try again.";
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Triggered when the user intends to read more on a specific topic.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MoreButton_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;

            ForumModel.Datum datum = (ForumModel.Datum)btn.DataContext;


            if (datum != null)
            {
                ForumWindow forumWindow = new ForumWindow();
                string      bodyText    = datum.body.ToString();
                string      TitleText   = datum.title.ToString();
                string      dateText    = datum.created.date.ToString();
                string      userName    = datum.user.name.ToString();
                string      AvaterUrl   = datum.user.avatarUrl.ToString();

                forumWindow.headerTB.Text     = "A forum post by: " + userName;
                forumWindow.bodyTB.Text       = bodyText;
                forumWindow.titleText.Text    = TitleText;
                forumWindow.dateText.Text     = dateText;
                forumWindow.usernameText.Text = userName;
                forumWindow.userImage.Source  = new BitmapImage(new Uri(AvaterUrl));
                //Reformat the body of comments to remove html tags

                foreach (var m in datum.comment.data)
                {
                    string theBody = m.body;

                    string   reformatted = Regex.Replace(theBody, @"<[^>]*>", "");
                    DateTime dateTime    = new DateTime();
                    bool     dateParse   = DateTime.TryParse(m.created.date, out dateTime);
                    //string date = dat.created.date;
                    if (dateParse)
                    {
                        string convertedTime = Convert.ToDateTime(DateTime.Parse(dateTime.ToString())).ToString(("ddd, dd MMM yyyy hh:mm:tt"));
                        m.created.date = convertedTime;
                    }
                    m.body = reformatted.Replace("<p>", "").Replace("<b>", "").Replace("</b>", "").Replace("</p>", "");

                    m.LoggedInID = LoggedID;
                }
                //Pass slug to the forum
                forumWindow.PostSlug = datum.slug;
                //Pass the token from this page.
                forumWindow.Token = Token;
                forumWindow.commentsListBox.ItemsSource = datum.comment.data;
                forumWindow.Show();
            }
        }
コード例 #3
0
        /// <summary>
        /// Handles the update of user posts.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void EditButton_Click(object sender, RoutedEventArgs e)
        {
            PostWindow postWindow = new PostWindow();
            string     tokenBuild = "Bearer " + Token;
            Button     btn        = sender as Button;

            ForumModel.Datum datum = (ForumModel.Datum)btn.DataContext;

            if (datum != null)
            {
                postWindow.theBlogPostControl.Visibility   = Visibility.Visible;
                postWindow.theStatusPostControl.Visibility = Visibility.Hidden;
                postWindow.theLinksControl.Visibility      = Visibility.Hidden;


                postWindow.titleText.Text = "Edit your forum post";
                //Reformat the titleBox to reflect the current text.
                postWindow.theBlogPostControl.TitleBox.Text = datum.title;

                string bodyConverted = datum.body;
                //Clear the TB
                postWindow.theBlogPostControl.RTBox.Document.Blocks.Clear();

                postWindow.theBlogPostControl.RTBox.AppendText(bodyConverted);

                postWindow.ShowDialog();
                string editedTitle = postWindow.theBlogPostControl.PostTitle;
                string editedBody  = postWindow.theBlogPostControl.PostBody;

                int    id       = datum.id;
                string endpoint = @"https://api.africoders.com/v1/edit/post?id=" + id.ToString() + "&title=" + editedTitle + "&body=" + editedBody;

                postHelper            = new PostHelper(endpoint);
                loadingTextBlock.Text = "Editing Post.";
                await postHelper.MakePostAsync(tokenBuild);

                if (postHelper.StatusPostSuccessful)
                {
                    loadingTextBlock.Text = "Edited Post Successfully.";
                    Refresh();
                }
                else
                {
                    loadingTextBlock.Text = "Unable to edit post. Please try again.";
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Fires when the user intends to make a comment.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void CommentButton_Click(object sender, RoutedEventArgs e)
        {
            string tkBuild = "Bearer " + Token;

            Button btn = sender as Button;

            ForumModel.Datum datum = (ForumModel.Datum)btn.DataContext;

            if (datum != null)
            {
                int Id = datum.id;
                commentPoster = new CommentPoster();
                PostWindow postWindow = new PostWindow();

                postWindow.theStatusPostControl.Visibility = Visibility.Visible;
                postWindow.theLinksControl.Visibility      = Visibility.Hidden;
                postWindow.theBlogPostControl.Visibility   = Visibility.Hidden;
                postWindow.ShowDialog();

                string comment = postWindow.theStatusPostControl.Body;


                loadingTextBlock.Text = "Making a comment...";

                await commentPoster.MakeAComment(tkBuild, Id, comment);

                if (commentPoster.success)
                {
                    loadingTextBlock.Text = "Commented Successfully.";
                    Refresh();
                }
                else
                {
                    loadingTextBlock.Text = "Unable to post your comment.";
                    //MessageBox.Show("Unable to comment at this time.");
                }
            }
        }