/// <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."; } } }
/// <summary> /// Make a comment to the provided endpoint. /// </summary> /// <param name="token"></param> /// <param name="postID"></param> /// <param name="comment"></param> /// <returns></returns> public async Task MakeAComment(string token, int postID, string comment) { CommentPostEndpoint = CommentPostEndpoint + "pid=" + postID + "&body=" + comment; postHelper = new PostHelper(CommentPostEndpoint); await postHelper.MakePostAsync(token); success = postHelper.StatusPostSuccessful; }
private async void EditButton_Click(object sender, RoutedEventArgs e) { Button editBtn = sender as Button; dynamic data = (dynamic)editBtn.DataContext; //Button to edit a comment. try { if (data != null) { //Edit the token. string tkBuild = "Bearer " + Token; //Get the id string id = data.id.ToString(); PostWindow postWindow = new PostWindow(); //Employ the status control for changing comments. postWindow.theStatusPostControl.Visibility = Visibility.Visible; postWindow.theBlogPostControl.Visibility = Visibility.Hidden; postWindow.theLinksControl.Visibility = Visibility.Hidden; MessageBox.Show(id + " " + Token); //First clear the placeholder text postWindow.theStatusPostControl.RTBox.Document.Blocks.Clear(); postWindow.titleText.Text = "Edit your comment."; postWindow.theStatusPostControl.RTBox.AppendText(data.body); postWindow.ShowDialog(); string body = postWindow.theStatusPostControl.Body; string endPoint = @"https://api.africoders.com/v1/edit/comment?id=" + id + "&body=" + body; postHelper = new PostHelper(endPoint); bottomPageText.Text = "Attempting to update comment. Please wait."; await postHelper.MakePostAsync(tkBuild); if (postHelper.StatusPostSuccessful) { bottomPageText.Text = "Comment successfully updated."; } else { bottomPageText.Text = "Unable to update comment at this time."; } } } catch (Exception t) { MessageBox.Show(t.Message); } }
private async void EditButton_Click(object sender, RoutedEventArgs e) { string tkBuild = "Bearer " + Token; Button editButton = sender as Button; Datum datum = (Datum)editButton.DataContext; if (datum != null) { PostWindow postWindow = new PostWindow(); //Get the post ID. int postID = datum.id; //Since this is a status post, only the body is needed. string body = datum.body; string title = datum.title; postWindow.theStatusPostControl.Visibility = Visibility.Hidden; postWindow.theBlogPostControl.Visibility = Visibility.Visible; postWindow.theLinksControl.Visibility = Visibility.Hidden; //First clear the textbox postWindow.theStatusPostControl.RTBox.Document.Blocks.Clear(); postWindow.theBlogPostControl.TitleBox.Clear(); //Append the message to be edited to the rich text box. postWindow.theBlogPostControl.RTBox.AppendText(body); postWindow.theBlogPostControl.TitleBox.Text = title; //We are ready for edit. postWindow.ShowDialog(); string returnEditedText = postWindow.theBlogPostControl.PostBody; string EditedTitle = postWindow.theBlogPostControl.PostTitle; string editEndpoint = @"https://api.africoders.com/v1/edit/post" + "?id=" + postID + "&title=" + EditedTitle + "&body=" + returnEditedText; postHelper = new PostHelper(editEndpoint); loadingTextBlock.Text = "Editing post..."; await postHelper.MakePostAsync(tkBuild); //MessageBox.Show("Post edited successfully."); loadingTextBlock.Text = "Post edited."; //Refresh Refresh(); } }
/// <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."; } } }
/// <summary> /// Make a status post. /// </summary> /// <param name="postBody">Message to be posted to the endpoint.</param> private async void MakePost(string postBody) { string tokenBuilder = "Bearer " + Token; statusPostEndpoint = statusPostEndpoint + postBody; postHelper = new PostHelper(statusPostEndpoint); await postHelper.MakePostAsync(tokenBuilder); if (postHelper.StatusPostSuccessful) { loadingTextBlock.Text = "Successfully Created a Status Post."; //reset the board immediately. Refresh(); } }
private async void DeleteButton_Click(object sender, RoutedEventArgs e) { Button btn = sender as Button; dynamic data = (dynamic)btn.DataContext; if (data != null) { try { string tkBuild = "Bearer " + Token; string id = data.id.ToString(); postHelper = new PostHelper(@"https://api.africoders.com/v1/del/comment?id=" + id); MessageBoxResult messageBoxResult = MessageBox.Show("Delete your comment?", "Comment Deletion.", MessageBoxButton.YesNo, MessageBoxImage.Question); switch (messageBoxResult) { case MessageBoxResult.Yes: bottomPageText.Text = "Deleting Comment.."; await postHelper.MakePostAsync(tkBuild); if (postHelper.StatusPostSuccessful) { bottomPageText.Text = "Comment Deleted."; } else { bottomPageText.Text = "Unable to delete comment at this time."; } break; case MessageBoxResult.No: return; } } catch (Exception d) { MessageBox.Show(d.Message); } } }
/// <summary> /// Handles the making of forum posts. Only authorised user can make posts. /// </summary> /// <param name="title"></param> /// <param name="body"></param> /// <param name="fid"></param> private async void MakeAForumPost(string title, string body, string fid) { string tkBuild = "Bearer " + Token; string endPoint = @"https://api.africoders.com/v1/post/forum?title=" + title + "&body=" + body + "&fid=" + fid; postHelper = new PostHelper(endPoint); loadingTextBlock.Text = "Making a forum post"; await postHelper.MakePostAsync(tkBuild); if (postHelper.StatusPostSuccessful) { loadingTextBlock.Text = "Posted Successfully"; //Refresh the page Refresh(); } else { loadingTextBlock.Text = "Unable to create post at this time. Please try again."; } }
/// <summary> /// Blog post helper method. /// </summary> /// <param name="title"></param> /// <param name="body"></param> private async void MakeBlogPost(string title, string body) { string tkBuilder = "Bearer " + Token; BlogPoseEndpoint = BlogPoseEndpoint + "title=" + title + "&body=" + body; postHelper = new PostHelper(BlogPoseEndpoint); await postHelper.MakePostAsync(tkBuilder); if (postHelper.StatusPostSuccessful) { loadingTextBlock.Text = "Blog Post Made Successfully."; //Refresh the control Refresh(); //MessageBox.Show("Posted Successfully."); } else { loadingTextBlock.Text = "Unable to make a post at this time. Please try again."; //MessageBox.Show("Unable to make a post at this time."); } }
/// <summary> /// Fires when the user intends to deletes own 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; Datum datum = (Datum)btn.DataContext; if (datum != null) { string postID = datum.id.ToString(); string deleteEndpoint = @"https://api.africoders.com/v1/del/post?id=" + postID; postHelper = new PostHelper(deleteEndpoint); loadingTextBlock.Text = "Deleting post..."; await postHelper.MakePostAsync(tokenBuild); loadingTextBlock.Text = "Post Deleted Successfully."; Refresh(); } }
/// <summary> /// Make a status post. /// </summary> /// <param name="postBody">Message to be posted to the endpoint.</param> private async void MakePost(string postBody, string postTitle, string url) { string tokenBuilder = "Bearer " + Token; LinkPostEndpoint = LinkPostEndpoint + "?title=" + postTitle + "&body=" + postBody + "&url=" + url; postHelper = new PostHelper(LinkPostEndpoint); await postHelper.MakePostAsync(tokenBuilder); if (postHelper.StatusPostSuccessful) { loadingTextBlock.Text = "Link Successfully Posted."; //MessageBox.Show("Posted."); //Refresh the control. Refresh(); } else { loadingTextBlock.Text = "Unable to post your link at this time. Please try again"; //MessageBox.Show("Unsucessful Operation."); } }
/// <summary> /// Make a status post. /// </summary> /// <param name="postBody">Message to be posted to the endpoint.</param> private async void MakePost(string postBody, string postTitle) { string tokenBuilder = "Bearer " + Token; jobPostEndpoint = jobPostEndpoint + "?title=" + postTitle + "&body=" + postBody; postHelper = new PostHelper(jobPostEndpoint); await postHelper.MakePostAsync(tokenBuilder); if (postHelper.StatusPostSuccessful == true) { loadingTextBlock.Text = "Job Opening Posted Successfully."; //MessageBox.Show("Posted."); //Refresh the control. Refresh(); } else { loadingTextBlock.Text = "Unable to post your job opening. Please try again."; //MessageBox.Show("Unsucessful Operation."); } }