void btnSubmitComment_Click(object sender, RoutedEventArgs e) { if (!JMMServerVM.Instance.Trakt_IsEnabled) { Utils.ShowErrorMessage(Properties.Resources.Anime_TraktNotEnabled); txtCommentNew.Focus(); return; } if (string.IsNullOrEmpty(JMMServerVM.Instance.Trakt_AuthToken)) { Utils.ShowErrorMessage(Properties.Resources.Anime_JMMAuth); txtCommentNew.Focus(); return; } AnimeSeriesVM animeSeries = (AnimeSeriesVM)this.DataContext; if (animeSeries == null) { Utils.ShowErrorMessage(Properties.Resources.Anime_SeriesNotFound); txtCommentNew.Focus(); return; } string commentText = txtCommentNew.Text.Trim(); if (string.IsNullOrEmpty(commentText)) { Utils.ShowErrorMessage(Properties.Resources.Anime_EnterText); txtCommentNew.Focus(); return; } if (commentText.Length > 2000) { Utils.ShowErrorMessage(string.Format(Properties.Resources.Anime_CommentText, commentText.Length)); txtCommentNew.Focus(); return; } btnSubmitComment.IsEnabled = false; if (animeSeries.AniDB_Anime.traktSummary != null) { string traktID = string.Empty; // check to see if this series is linked to more than one Trakt series if (animeSeries.AniDB_Anime.traktSummary.traktDetails == null || animeSeries.AniDB_Anime.traktSummary.traktDetails.Count == 0) { Utils.ShowErrorMessage(string.Format(Properties.Resources.Anime_NoTrakt)); txtCommentNew.Focus(); btnSubmitComment.IsEnabled = true; return; } // check to see if this series is linked to more than one Trakt series if (animeSeries.AniDB_Anime.traktSummary.traktDetails != null && animeSeries.AniDB_Anime.traktSummary.traktDetails.Count > 1) { Utils.ShowErrorMessage(string.Format(Properties.Resources.Anime_MultiTrakt)); txtCommentNew.Focus(); btnSubmitComment.IsEnabled = true; return; } if (animeSeries.AniDB_Anime.traktSummary.traktDetails != null && animeSeries.AniDB_Anime.traktSummary.traktDetails.Count == 1) { this.Cursor = Cursors.Wait; foreach (KeyValuePair<string, TraktDetails> kvp in animeSeries.AniDB_Anime.traktSummary.traktDetails) { traktID = kvp.Key; } Trakt_CommentPost comment = new Trakt_CommentPost(); comment.TraktID = traktID; comment.AnimeID = animeSeries.AniDB_ID; comment.CommentText = commentText; comment.Spoiler = chkSpoiler.IsChecked.Value; postCommenttWorker.RunWorkerAsync(comment); } } else { Utils.ShowErrorMessage(string.Format(Properties.Resources.Anime_NoTrakt)); txtCommentNew.Focus(); btnSubmitComment.IsEnabled = true; } }
void btnSubmitComment_Click(object sender, RoutedEventArgs e) { if (!JMMServerVM.Instance.Trakt_IsEnabled) { Utils.ShowErrorMessage("You have not enabled Trakt, for more info go to 'Settings - Community Sites - Trakt TV'"); txtCommentNew.Focus(); return; } if (string.IsNullOrEmpty(JMMServerVM.Instance.Trakt_AuthToken)) { Utils.ShowErrorMessage("You have not authorized JMM to use your Trakt account, for more info go to 'Settings - Community Sites - Trakt TV'"); txtCommentNew.Focus(); return; } AnimeSeriesVM animeSeries = (AnimeSeriesVM)this.DataContext; if (animeSeries == null) { Utils.ShowErrorMessage("Anime series info not found"); txtCommentNew.Focus(); return; } string commentText = txtCommentNew.Text.Trim(); if (string.IsNullOrEmpty(commentText)) { Utils.ShowErrorMessage("Please enter text for your comment"); txtCommentNew.Focus(); return; } if (commentText.Length > 2000) { Utils.ShowErrorMessage(string.Format("Comment text must be less than 2000 characters ({0})", commentText.Length)); txtCommentNew.Focus(); return; } btnSubmitComment.IsEnabled = false; if (animeSeries.AniDB_Anime.traktSummary != null) { string traktID = string.Empty; // check to see if this series is linked to more than one Trakt series if (animeSeries.AniDB_Anime.traktSummary.traktDetails == null || animeSeries.AniDB_Anime.traktSummary.traktDetails.Count == 0) { Utils.ShowErrorMessage(string.Format("Cannot comment where a series does not have a Trakt show linked")); txtCommentNew.Focus(); btnSubmitComment.IsEnabled = true; return; } // check to see if this series is linked to more than one Trakt series if (animeSeries.AniDB_Anime.traktSummary.traktDetails != null && animeSeries.AniDB_Anime.traktSummary.traktDetails.Count > 1) { Utils.ShowErrorMessage(string.Format("Cannot comment where a series has more than one Trakt show linked")); txtCommentNew.Focus(); btnSubmitComment.IsEnabled = true; return; } if (animeSeries.AniDB_Anime.traktSummary.traktDetails != null && animeSeries.AniDB_Anime.traktSummary.traktDetails.Count == 1) { this.Cursor = Cursors.Wait; foreach (KeyValuePair<string, TraktDetails> kvp in animeSeries.AniDB_Anime.traktSummary.traktDetails) { traktID = kvp.Key; } Trakt_CommentPost comment = new Trakt_CommentPost(); comment.TraktID = traktID; comment.AnimeID = animeSeries.AniDB_ID; comment.CommentText = commentText; comment.Spoiler = chkSpoiler.IsChecked.Value; postCommenttWorker.RunWorkerAsync(comment); } } else { Utils.ShowErrorMessage(string.Format("Cannot comment where a series does not have a Trakt show linked")); txtCommentNew.Focus(); btnSubmitComment.IsEnabled = true; } }