protected void Page_Load(object sender, EventArgs e) { btnSearch.Text = DictionaryConstants.GoButtonText; txtSearch.Attributes.Add("placeholder", DictionaryConstants.Community_EnterConversation); if (!IsPostBack) { ResultCount = 10; Item currItem = Sitecore.Context.Item; if (currItem != null) { hrfBack.HRef = LinkManager.GetItemUrl(currItem.Parent); litBack.Text = currItem.Parent.Name; ForumItem frmItem = new ForumItem(currItem); Session["forumItem"] = frmItem; if (frmItem != null) { ForumModel frmModel = Forum.ForumModelFactory(frmItem); litForumName.Text = frmModel.Name; if (frmModel != null) { Session["_threads"] = frmModel.Threads; rptThread.DataSource = frmModel.Threads.Take(ResultSet) ; rptThread.DataBind(); } } } } }
protected void Page_Load(object sender, EventArgs e) { rqdDropDownFName.Enabled = String.IsNullOrEmpty(txtFName.Text); txtFName.Text = HiddenText; if (!IsPostBack) { ddlForums.Items.Add(new ListItem() { Value = "0", Text = InitialDropDownText }); txtFName.Attributes.Add("placeholder", InitialTextBoxText); ddlForums.ValidationGroup = validation_group; txtFName.ValidationGroup = validation_group; btnSubmit.ValidationGroup = validation_group; rqdDropDownFName.ValidationGroup = validation_group; rqdDiscussion.ValidationGroup = validation_group; rqdSubject.ValidationGroup = validation_group; //Are we on a forum or Group?? Item currItem = Sitecore.Context.Item; if (currItem.TemplateID.ToString().Equals(GroupItem.TemplateId)) { GroupItem grpItem = new GroupItem(currItem); Session["_item"] = grpItem; GroupCardModel grpModel = Groups.GroupCardModelFactory(grpItem); List<ForumModel> frms =currItem.Children.Select(x => Forum.ForumModelFactory(new ForumItem(x))).ToList<ForumModel>(); if (grpModel != null) { ddlForums.DataSource = frms; ddlForums.DataBind(); } } else { if (currItem.TemplateID.ToString().Equals(ForumItem.TemplateId)) { ForumItem frmItem = new ForumItem(currItem); Session["_item"] = frmItem; //Disable forum selection and select ddlForums.Enabled = false; ddlForums.Visible = false; txtFName.Visible = true; txtFName.Text = frmItem.DisplayName; txtFName.Enabled = false; } } } }
public static Item CreateSitecoreForumThread(ThreadModel thModel, ForumItem frmItem, Language lang) { Item newItem = null; try { if (thModel != null && frmItem != null && lang != null) { //Again we need to handle security //In this example we just disable it using (new SecurityDisabler()) { //First get the parent item from the master database Database masterDb = global:: Sitecore.Configuration.Factory.GetDatabase("master"); Item parentItem = masterDb.Items[frmItem.InnerItem.Paths.Path, lang]; //Now we need to get the template from which the item is created (Forum Thread Template) TemplateItem template = masterDb.GetTemplate(ThreadModel.TemplateID); //StringBuilder sb = new StringBuilder(ItemName.Trim()); // string newName = ItemName.Replace('.', '_');//.Substring(0, ItemName.LastIndexOf(".")); // if(newName.Contains(".")) // newName=newName.Substring(newName.IndexOf(".") + 1); newItem = masterDb.GetItem(parentItem.Paths.Path + "/" + thModel.Subject, lang); if (newItem == null) { //Now we can add the new item as a child to the parent newItem = parentItem.Add(thModel.Subject, template); } //We can now manipulate the fields and publish as in the previous example //Item item = masterDb.GetItem(newItem); //Begin editing newItem.Editing.BeginEdit(); try { //perform the editing newItem.Fields["ForumID"].Value = thModel.ForumID; newItem.Fields["ThreadID"].Value = thModel.ThreadID; newItem.Fields["Body"].Value = thModel.Body; newItem.Fields["Subject"].Value = thModel.Subject; // errorState = true; } catch (Exception ex) { // errorState = false; throw ex; } finally { //Close the editing state newItem.Editing.EndEdit(); } } } } catch (Exception ex) { //Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Error with :" + ItemName + " (" + lang.Name + ")\n Details:\n" + ex.Message)); Sitecore.Diagnostics.Error.LogError("Error with :" + thModel.Subject + " (" + lang.Name + ")\n Details:\n" + ex.Message); newItem = null; } return newItem ; }
public static ForumModel ForumModelFactory(ForumItem item) { ForumModel frm = new ForumModel(item, TelligentService.TelligentService.ReadThreadList); return frm; }
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); } }