protected void btnSaveContentForm__Click(object sender, ImageClickEventArgs e) { long id = _contentId.Text.Trim() == "" ? 0 : Convert.ToInt64(_contentId.Text); string cultureCode = App_Code.SessionInfo.CurrentSite.cultureCode; awContent content = new awContent(); bool newContent = false; try { if (id == 0) //Add new content { newContent = true; id = AWAPI_Common.library.MiscLibrary.CreateUniqueId(); } else //update the content { content = _contentLib.Get(id); if (content == null) { AdminMaster.WriteMessage(AWAPI.Admin.AdminMaster.MessageType.ERROR, "Content not found."); return; } } content.siteId = App_Code.SessionInfo.CurrentSite.siteId; content.userId = App_Code.SessionInfo.CurrentUser.userId; #region SAVE CONTENT STATIC VALUES //SAVE THE CONTENT, FIRST (STATIC VALUES ONLY ) ---------------------------------------------- foreach (GridViewRow gr in _contentFieldList.Rows) { Boolean isCustomField = ((CheckBox)gr.FindControl("_isContentCustomField")).Checked; string fieldName = ((Literal)gr.FindControl("_title")).Text.ToLower().Trim(); string fieldType = ((Literal)gr.FindControl("_fieldType")).Text.ToLower(); Literal tmpContentCustomFieldId = (Literal)gr.FindControl("_contentCustomFieldId"); long contentCustomFieldId = (tmpContentCustomFieldId.Text == "" || tmpContentCustomFieldId.Text == "0") ? 0 : Convert.ToInt64(tmpContentCustomFieldId.Text); TextBox txb = (TextBox)gr.FindControl("_editBox"); CheckBox cb = (CheckBox)gr.FindControl("_checkBox"); if (!newContent && isCustomField && contentCustomFieldId > 0) { _customLib.UpdateFieldValue(id, contentCustomFieldId, App_Code.SessionInfo.CurrentUser.userId, txb.Text, cultureCode); } else { SetContentStaticValues(fieldName, txb.Text, cb.Checked, content); } } #endregion if (content.alias == null || content.alias.Trim() == "") { if (content.title.Trim() != "") { content.alias = AWAPI_Common.library.MiscLibrary.FormatAliasName(content.title); } else { content.alias = AWAPI_Common.library.MiscLibrary.FormatAliasName(_formTitle.Text.Trim() + "_" + id.ToString()); } } #region ADD or UPDATE CONTENT if (newContent) { content.parentContentId = 0; if (_formFeature_applyToSub.Checked && _formFeature_contentId.Text != "") { content.parentContentId = Convert.ToInt64(_formFeature_contentId.Text); } id = _contentLib.Add(id, content.alias, content.title, content.description, content.contentType, content.siteId, content.userId, content.parentContentId, content.eventStartDate, content.eventEndDate, content.link, content.imageurl, content.sortOrder, content.isEnabled, content.isCommentable, content.pubDate, content.pubEndDate); _contentId.Text = id.ToString(); } else { _contentLib.Update(id, content.alias, content.title, content.description, content.contentType, content.userId, content.parentContentId, content.eventStartDate, content.eventEndDate, content.link, content.imageurl, content.sortOrder, content.isEnabled, content.isCommentable, content.pubDate, content.pubEndDate); } #endregion #region SAVE CONTENT CUSTOM FIELDS //SAVE THE CUSTOM FIELDS foreach (GridViewRow gr in _contentFieldList.Rows) { Boolean isCustomField = ((CheckBox)gr.FindControl("_isContentCustomField")).Checked; Literal tmpContentCustomFieldId = (Literal)gr.FindControl("_contentCustomFieldId"); long contentCustomFieldId = (tmpContentCustomFieldId.Text == "" || tmpContentCustomFieldId.Text == "0") ? 0 : Convert.ToInt64(tmpContentCustomFieldId.Text); if (!isCustomField || contentCustomFieldId <= 0) { continue; } string fieldType = ((Literal)gr.FindControl("_fieldType")).Text.ToLower(); TextBox txb = (TextBox)gr.FindControl("_editBox"); CheckBox cb = (CheckBox)gr.FindControl("_checkBox"); string value = txb.Text; if (fieldType == "checkbox") { value = cb.Checked.ToString(); } _customLib.UpdateFieldValue(id, contentCustomFieldId, App_Code.SessionInfo.CurrentUser.userId, value, cultureCode); } #endregion PopulateFields(Convert.ToInt64(_formFeature_formId.Text), id); if (_formFeature_applyToSub.Checked) { PopulateChildContentList(Convert.ToInt64(_formFeature_contentId.Text)); } AdminMaster.WriteMessage(AWAPI.Admin.AdminMaster.MessageType.INFO, "Content has been saved."); } catch (Exception ex) { AdminMaster.WriteMessage(AWAPI.Admin.AdminMaster.MessageType.ERROR, ex.Message); } }
protected void btnSaveContent_Click(object sender, ImageClickEventArgs e) { long contentId = _contentId.Text.Trim().Length == 0 ? 0 : Convert.ToInt64(_contentId.Text); bool newContent = false; awContent content = new awContent(); content.alias = _alias.Text; content.title = _title.Text; content.description = _description.Value; content.link = ""; content.imageurl = _contentImageUrl.Text; content.userId = App_Code.SessionInfo.CurrentUser.userId; content.contentType = AWAPI_Common.values.TypeValues.ContentTypes.content.ToString(); content.parentContentId = Convert.ToInt64(_contentParentList.SelectedValue); if (contentId != 0 && //if content is selected !String.IsNullOrEmpty(_culture.SelectedValue) && !String.IsNullOrEmpty(App_Code.SessionInfo.CurrentSite.cultureCode) && App_Code.SessionInfo.CurrentSite.cultureCode != _culture.SelectedValue) { _contentLib.SaveContentLanguage(Convert.ToInt64(_contentId.Text), _culture.SelectedValue.ToLower(), content.title, content.description, content.link, content.imageurl, content.userId); } else { content.eventStartDate = AWAPI_Common.library.MiscLibrary.ConvertStringToDate(_contentEventStartDate.Text); content.eventEndDate = AWAPI_Common.library.MiscLibrary.ConvertStringToDate(_contentEventEndDate.Text, true); content.pubDate = AWAPI_Common.library.MiscLibrary.ConvertStringToDate(_contentPublishStartDate.Text); content.pubEndDate = AWAPI_Common.library.MiscLibrary.ConvertStringToDate(_contentPublishEndDate.Text, true); content.siteId = App_Code.SessionInfo.CurrentSite.siteId; if (_contentSortOrder.Text.Trim() != "") { content.sortOrder = Convert.ToInt32(_contentSortOrder.Text); } content.isEnabled = cbStatusContent_.Checked; content.isCommentable = _contentIsCommentable.Checked; if (contentId == 0) { newContent = true; contentId = _contentLib.Add(content.alias, content.title, content.description, content.contentType, content.siteId, content.userId, content.parentContentId, content.eventStartDate, content.eventEndDate, content.link, content.imageurl, content.sortOrder, content.isEnabled, content.isCommentable, content.pubDate, content.pubEndDate); _contentId.Text = contentId.ToString(); } else { contentId = Convert.ToInt64(_contentId.Text); _contentLib.Update(contentId, content.alias, content.title, content.description, content.contentType, content.userId, content.parentContentId, content.eventStartDate, content.eventEndDate, content.link, content.imageurl, content.sortOrder, content.isEnabled, content.isCommentable, content.pubDate, content.pubEndDate); } } SaveContentsTags(contentId); SaveCustomFields(contentId); SetImage(content.imageurl); ShowHideContentButtons(true, content.contentType); PopulateContentList(); PopulateContentParentList(content.contentId); PopulateContentsTags(contentId); if (newContent) { PopulateCustomFields(contentId, content.parentContentId); } _contentParentList.SelectedValue = content.parentContentId.ToString(); AdminMaster.WriteMessage(AWAPI.Admin.AdminMaster.MessageType.INFO, "Content has been saved."); HighlightContentNode("saved", new TreeNode(content.alias, content.contentId.ToString()), twContent.Nodes); }