本文整理汇总了C#中Topic.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Topic.Save方法的具体用法?C# Topic.Save怎么用?C# Topic.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Topic
的用法示例。
在下文中一共展示了Topic.Save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
/*==========================================================================================================================
| METHOD: SAVE
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Will save any topic and, optionally, its children.
/// </summary>
/// <remarks>
/// <para>
/// In addition to acting as a pass-through for <see cref="Topic.Save(bool, bool)"/>, this also ensures that a) the
/// topic is saved twice (to account for serialized topic references, such as <c>ParentId</c>), and b) the <see
/// cref="ContentTypes"/> collection is first synchronized with the <see cref="TopicRepository"/>, and then the
/// TopicRepository state is restored to its original.
/// </para>
/// <para>
/// The one dependency that remains on the TopicRepository is in the Save() method, which relies on it as a centralized
/// source for attribute metadata - and, specifically, whether an attribute should be indexed or not.To mitigate this,
/// this method will ensure all local content types are saved to the TopicRepository.
/// </para>
/// </remarks>
/// <note>
/// IMPORTANT: If a <see cref="ContentType"/> with the same key exists, it will be overwritten. This ensures any
/// attributes added via the configuration scripts are reflected in the database. It also means, however, that the
/// TopicRepository's <see cref="TopicRepository.ContentTypes"/> collection will be orphaned from the TopicRepository's
/// configuration namespace. For that reason, the ContentTypes collection must be reset after a Save();
/// </note>
/// <param name="topic">The topic object.</param>
/// <param name="isRecursive">
/// Boolean indicator nothing whether to recurse through the topic's descendants and save them as well.
/// </param>
/// <param name="isDraft">Boolean indicator as to the topic's publishing status.</param>
void Save(Topic topic, bool isRecursive = false, bool isDraft = false)
{
/*------------------------------------------------------------------------------------------------------------------------
| Validate input
\-----------------------------------------------------------------------------------------------------------------------*/
Contract.Requires<ArgumentNullException>(topic != null, "The topic must be specified.");
/*------------------------------------------------------------------------------------------------------------------------
| Ensure TopicRepository references the local instances of the ContentTypes
\-----------------------------------------------------------------------------------------------------------------------*/
TopicRepository.ContentTypes = ContentTypes;
/*------------------------------------------------------------------------------------------------------------------------
| Save new configuration
\-----------------------------------------------------------------------------------------------------------------------*/
topic.Save(isRecursive, isDraft);
/*------------------------------------------------------------------------------------------------------------------------
| Update Derived Topic references to ensure any newly assigned IDs are available
\-----------------------------------------------------------------------------------------------------------------------*/
UpdateDerivedTopics(topic, isRecursive);
/*------------------------------------------------------------------------------------------------------------------------
| Update TopicID references
\-----------------------------------------------------------------------------------------------------------------------*/
topic.Save(isRecursive, isDraft);
/*------------------------------------------------------------------------------------------------------------------------
| Reset the TopicRepository's ContentType's cache so it isn't orphaned from the TopicRepository's configuration
\-----------------------------------------------------------------------------------------------------------------------*/
TopicRepository.ContentTypes = null;
}