public void UpdateItem(Item item) { // TODO: This isn't working properly.. // Make it so that you can updaet a draft item. If item is out of draft, but not published, lock down var existingContentItem = contentController.GetContentItem(item.ContentItemId); var newContentItem = new ContentItem { ContentKey = item.ContentKey.ToString(), ContentTypeId = this.ItemContentType.ContentTypeId, ModuleID = item.ModuleId }; newContentItem.Content = item.ItemDescription; // This could be empty... Or it could be your item serialized and this is then used as the main content store or as the main content store for versioned items newContentItem.Metadata["Name"] = item.ItemName; // Doesn't need to be here newContentItem.Metadata["Published"] = Convert.ToString(false); // This could be a field on a separate data store this.contentController.AddContentItem(newContentItem); String currentWorkflow = workflowController.GetStateName(newContentItem); if (String.IsNullOrEmpty(currentWorkflow)) { int workflowId = -1; if (moduleController.GetModule(item.ModuleId).ModuleSettings.Contains("Workflow")) { workflowId = int.Parse(moduleController.GetModule(item.ModuleId).ModuleSettings["Workflow"].ToString()); } workflowController.StartWorkflow(newContentItem, workflowId); } }
private void AddToContent(int contentItemId, Action <ContentItem> action) { var contentItem = _contentController.GetContentItem(contentItemId); action(contentItem); _contentController.UpdateContentItem(contentItem); }
private void PerformWorkflowActionOnStateChanged(StateTransaction stateTransaction, WorkflowActionTypes actionType) { var contentItem = _contentController.GetContentItem(stateTransaction.ContentItemId); var workflowAction = GetWorkflowActionInstance(contentItem, actionType); if (workflowAction != null) { workflowAction.DoActionOnStateChanged(stateTransaction); } }
public void DoActionOnStateChanged(StateTransaction stateTransaction) { // Workflow discarded, delete the item ContentItem contentItem = contentController.GetContentItem(stateTransaction.ContentItemId); if (contentItem != null) { contentController.DeleteContentItem(contentItem); } }
/// <summary> /// This removes a content item associated with a question/thread from the data store. Should run every time an entire thread is deleted. /// </summary> /// <param name="contentItemId"></param> public void DeleteContentItem(int contentItemId) { if (contentItemId <= Null.NullInteger) { return; } var contentItem = _contentController.GetContentItem(contentItemId); if (contentItem == null) { return; } // remove any metadata/terms associated first (perhaps we should just rely on ContentItem cascade delete here?) var cntTerms = new TermsImpl(); cntTerms.RemoveQuestionTerms(contentItem); _contentController.DeleteContentItem(contentItem); }
public void DoActionOnStateChanged(StateTransaction stateTransaction) { // Publish the new item ContentItem contentItem = contentController.GetContentItem(stateTransaction.ContentItemId); bool contentPendingDelete = false; if (contentItem.Metadata["PendingDelete"] != null) { bool.TryParse(contentItem.Metadata["PendingDelete"].ToString(), out contentPendingDelete); } if (contentPendingDelete) { // TODO: This should be dynamic... If not a module.. foreach (ContentItem content in contentController.GetContentItemsByModuleId(contentItem.ModuleID).Where(i => i.ContentTypeId != 2)) { // Delete all items with the same content key if (content.ContentKey == contentItem.ContentKey) { contentController.DeleteContentItem(content); } } } else { contentItem.Metadata["Published"] = Convert.ToString(true); // Unpublish the old item, will be treated as history ContentItem lastPublishedContentItem = contentController.GetContentItemsByModuleId(contentItem.ModuleID).Where(i => i.ContentKey == contentItem.ContentKey && i.Metadata["Published"] == Convert.ToString(true)).FirstOrDefault(); if (lastPublishedContentItem != null) { lastPublishedContentItem.Metadata["Published"] = Convert.ToString(false); contentController.UpdateContentItem(lastPublishedContentItem); } // TODO: This was unpublished.. It should be recorded somewhere that it was unpublished // due to a new update being published contentController.UpdateContentItem(contentItem); } }