protected void btnSubmit_Click(object sender, EventArgs e) { var frmItem = Session["forumItem"] as ForumItem; Item threadItem = null; if (frmItem != null) { //Grab information from fields string subject = txtSubject.Text; string body = txtBody.Text; string frmId = frmItem.ForumID.Text; try { //Create item in Telligent ThreadModel thModel = TelligentService.CreateForumThread(CurrentMember.ScreenName, frmId, subject, body); if (thModel != null) { //Create item in sitecore with returned forumID and threadID threadItem = Discussion.CreateSitecoreForumThread(thModel, frmItem, Sitecore.Context.Language); if (threadItem != null) { Response.Redirect("/Community and Events/Groups/" + ddlGroups.SelectedItem.Value); } else { //error handling } } } catch (Exception ex) { Sitecore.Diagnostics.Error.LogError(ex.Message); } } }
protected void btnSubmit_Click(object sender, EventArgs e) { //Client side validation passed if (CurrentMember != null && !String.IsNullOrEmpty(CurrentMember.ScreenName)) { //Grab information from fields string subject = txtSubject.Text; string body = txtBody.Text; string frmItemID = String.Empty; try { GroupItem grpItem = Session["_item"] as GroupItem; ForumItem frmItem = Session["_item"] as ForumItem; if (grpItem != null) { ///Go through selection process if (!ddlForums.SelectedValue.Equals("0")) //If forum was selected { frmItemID = ddlForums.SelectedIndex > -1 ? ddlForums.SelectedValue : String.Empty; } else if (!String.IsNullOrEmpty(txtFName.Text)) //If a name was input { frmItemID = new ForumItem(Forum.ConvertForumNametoSitecoreItem(txtFName.Text)).ForumID; //Create forum and return ForumID // ForumModel frmModel = TelligentService.CreateForum(CurrentMember.ScreenName, grpItem.GroupID.Text, txtFName.Text); // if (frmModel != null) // { // Item frmItemLocal = Forum.CreateSitecoreForum(frmModel, grpItem, Sitecore.Context.Language); // if (frmItemLocal != null) // { // //Success // frmItemID = frmModel.ForumID; // //Publish sitecore item // PublishItem(frmItemLocal); // } // else // { // //Delete Telligent Forum // TelligentService.DeleteForum(frmModel.ForumID); // var msg = "Error creating forum item in sitecore"; // Sitecore.Diagnostics.Error.LogError(msg); // error_msg.Text = msg; // error_msg.Visible = true; // ShowClientSideForm(); // return; // } // } // else // { // var msg = "Error creating forum item in Telligent."; // Sitecore.Diagnostics.Error.LogError(msg); // error_msg.Text = msg; // error_msg.Visible = true; // ShowClientSideForm(); // return; // } } else { var msg = DictionaryConstants.ErrorSelectingForumMessage; Sitecore.Diagnostics.Error.LogError(msg); error_msg.Text = msg; error_msg.Visible = true; ShowClientSideForm(HiddenText); return; } } if (frmItem != null) { frmItemID = frmItem.ForumID.Text; HiddenText = frmItem.DisplayName; } Item threadItem = null; if (!String.IsNullOrEmpty(frmItemID)) { try { //Create item in Telligent ThreadModel thModel = TelligentService.CreateForumThread(CurrentMember.ScreenName, frmItemID, subject, body); if (thModel != null) { //Create item in sitecore with returned forumID and threadID threadItem = Discussion.CreateSitecoreForumThread(thModel, frmItemID, Sitecore.Context.Language); if (threadItem != null) { error_msg.Visible = false; //Redirect to discussion //Publish thread item PublishItem(threadItem); //Sitecore.Web.WebUtil.Redirect(Sitecore.Links.LinkManager.GetItemUrl(threadItem)); /// clientsideScript("alert('" +String.Format( DictionaryConstants.ForumCreateConfirmation,subject)+"');"); Page.Response.Redirect(Page.Request.Url.ToString(), false); } else { //Delete from Telligent TelligentService.DeleteForumThread(frmItemID, thModel.ThreadID); error_msg.Text = DictionaryConstants.FailedToCreateDiscussionError; error_msg.Visible = true; ShowClientSideForm(HiddenText); } } else { //The assumption is that if the Thread is null, then there was an error in telligent API call and nothing was created error_msg.Text = DictionaryConstants.FailedToCreateDiscussionError; error_msg.Visible = true; ShowClientSideForm(HiddenText); } } catch (Exception ex) { Sitecore.Diagnostics.Error.LogError(ex.Message); error_msg.Text = DictionaryConstants.FailedToCreateDiscussionError; error_msg.Visible = true; ShowClientSideForm(HiddenText); } } } catch (Exception ex) { Sitecore.Diagnostics.Error.LogError("Error creating forum item in btnSubmit_Click.\nError:\n " + ex.Message); error_msg.Text = DictionaryConstants.DiscussionCriticalErrorMessage; error_msg.Visible = true; ShowClientSideForm(HiddenText); } } else { error_msg.Text = "You are not logged on."; error_msg.Visible = true; ShowClientSideForm(HiddenText); } }