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


C# Post.SetCustomProperties方法代码示例

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


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

示例1: Create

		protected Post Create(Topic topic, Post post, String subject, String message, IDictionary<String, Object> customProperties) {
			if (topic == null) {
				throw new ArgumentNullException("topic");
			}
			if (String.IsNullOrWhiteSpace(subject)) {
				throw new ArgumentNullException("subject");
			}
			if (String.IsNullOrWhiteSpace(message)) {
				throw new ArgumentNullException("message");
			}
			// Let's get the topic from the data-storage!
			topic = this.topicRepo.Read(t => t.Id == topic.Id);
			if (topic == null) {
				throw new ArgumentException("topic does not exist");
			}
			if (post != null) {
				// Let's get the topic from the data-storage!
				post = this.postRepo.Read(po => po.Id == post.Id);
				if (post == null) {
					throw new ArgumentException("post does not exist");
				}
			}

			this.logger.WriteFormat("Create called on PostService, subject: {0}, topic id: {1}", subject, topic.Id);
			AccessFlag flag = this.permService.GetAccessFlag(this.userProvider.CurrentUser, topic.Forum);
			if ((flag & AccessFlag.Reply) != AccessFlag.Reply) {
				this.logger.WriteFormat("User does not have permissions to create a new post in topic {1}, subject: {0}", subject, topic.Id);
				throw new PermissionException("post, create");
			}

			Post p = new Post {
				Author = this.userProvider.CurrentUser,
				AuthorId = this.userProvider.CurrentUser.Id,
				Changed = DateTime.UtcNow,
				Created = DateTime.UtcNow,
				Editor = this.userProvider.CurrentUser,
				EditorId = this.userProvider.CurrentUser.Id,
				Topic = topic,
				TopicId = topic.Id,
				Forum = topic.Forum,
				ForumId = topic.ForumId,
				Message = message,
				State = PostState.None,
				Subject = subject
			};
			p.SetCustomProperties(customProperties);

			// Was a parent post given?
			if (post != null) {
				// Let's store that then, for the "tree" view (and other features)
				p.ParentPost = post;
				p.ParentPostId = post.Id;
			}

			this.postRepo.Create(p);
			this.logger.WriteFormat("Post created in PostService, Id: {0}", p.Id);
			this.eventPublisher.Publish<PostCreated>(new PostCreated {
				Post = p
			});
			this.logger.WriteFormat("Create events in PostService fired, Id: {0}", p.Id);

			return p;
		}
开发者ID:razzles67,项目名称:NForum,代码行数:63,代码来源:PostService.cs


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