当前位置: 首页>>代码示例>>C#>>正文


C# Topic.SetCustomProperties方法代码示例

本文整理汇总了C#中Topic.SetCustomProperties方法的典型用法代码示例。如果您正苦于以下问题:C# Topic.SetCustomProperties方法的具体用法?C# Topic.SetCustomProperties怎么用?C# Topic.SetCustomProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Topic的用法示例。


在下文中一共展示了Topic.SetCustomProperties方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Create

		/// <summary>
		/// Method for creating a new topic.
		/// </summary>
		/// <param name="forum">The parent forum of the topic.</param>
		/// <param name="subject">The subject of the topic.</param>
		/// <param name="message">The content/message of the topic.</param>
		/// <param name="type">The type of the topic </param>
		/// <param name="customPropties"></param>
		/// <returns>The newly created topic.</returns>
		public Topic Create(Forum forum, String subject, String message, TopicType type, IDictionary<String, Object> customPropties = null) {
			if (forum == null) {
				throw new ArgumentNullException("forum");
			}
			if (String.IsNullOrWhiteSpace(subject)) {
				throw new ArgumentNullException("subject");
			}
			if (String.IsNullOrWhiteSpace(message)) {
				throw new ArgumentNullException("message");
			}
			forum = this.forumRepo.Read(f => f.Id == forum.Id);
			if (forum == null) {
				throw new ArgumentException("forum does not exist");
			}

			this.logger.WriteFormat("Create called on TopicService, subject: {0}, forum id: {1}", subject, forum.Id);
			AccessFlag flag = this.permService.GetAccessFlag(this.userProvider.CurrentUser, forum);
			if ((flag & AccessFlag.Create) != AccessFlag.Create) {
				this.logger.WriteFormat("User does not have permissions to create a new topic in forum {1}, subject: {0}", subject, forum.Id);
				throw new PermissionException("topic, create");
			}
			if (type != TopicType.Regular && (flag & AccessFlag.Priority) != AccessFlag.Priority) {
				this.logger.WriteFormat("User does not have permissions to set topic type on new topic in forum {1}, subject: {0}", subject, forum.Id);
				throw new PermissionException("topic, type");
			}

			Topic t = new Topic {
				Author = this.userProvider.CurrentUser,
				AuthorId = this.userProvider.CurrentUser.Id,
				Changed = DateTime.UtcNow,
				Created = DateTime.UtcNow,
				Editor = this.userProvider.CurrentUser,
				EditorId = this.userProvider.CurrentUser.Id,
				Forum = forum,
				ForumId = forum.Id,
				Message = message,
				State = TopicState.None,
				Subject = subject,
				Type = type
			};
			t.SetCustomProperties(customPropties);

			this.topicRepo.Create(t);
			this.logger.WriteFormat("Topic created in TopicService, Id: {0}", t.Id);
			this.eventPublisher.Publish<TopicCreated>(new TopicCreated {
				Topic = t
			});
			this.logger.WriteFormat("Create events in TopicService fired, Id: {0}", t.Id);

			return t;
		}
开发者ID:razzles67,项目名称:NForum,代码行数:60,代码来源:TopicService.cs


注:本文中的Topic.SetCustomProperties方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。