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


C# User.IsInRole方法代码示例

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


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

示例1: UndeleteTopic

		public void UndeleteTopic(Topic topic, User user)
		{
			if (user.IsInRole(PermanentRoles.Moderator))
			{
				_moderationLogService.LogTopic(user, ModerationType.TopicUndelete, topic, null);
				_topicRepository.UndeleteTopic(topic.TopicID);
				RecalculateReplyCount(topic);
				var forum = _forumService.Get(topic.ForumID);
				_forumService.UpdateCounts(forum);
				_forumService.UpdateLast(forum);
			}
			else
				throw new InvalidOperationException("User must be Moderator to undelete topic.");
		}
开发者ID:andyliyuze,项目名称:POPForums,代码行数:14,代码来源:TopicService.cs

示例2: UpdateTitleAndForum

		public void UpdateTitleAndForum(Topic topic, Forum forum, string newTitle, User user)
		{
			if (user.IsInRole(PermanentRoles.Moderator))
			{
				var oldTopic = _topicRepository.Get(topic.TopicID);
				if (oldTopic.ForumID != forum.ForumID)
					_moderationLogService.LogTopic(user, ModerationType.TopicMoved, topic, forum, String.Format("Moved from {0} to {1}", oldTopic.ForumID, forum.ForumID));
				if (oldTopic.Title != newTitle)
					_moderationLogService.LogTopic(user, ModerationType.TopicRenamed, topic, forum, String.Format("Renamed from \"{0}\" to \"{1}\"", oldTopic.Title, newTitle));
				var urlName = newTitle.ToUniqueUrlName(_topicRepository.GetUrlNamesThatStartWith(newTitle.ToUrlName()));
				topic.UrlName = urlName;
				_topicRepository.UpdateTitleAndForum(topic.TopicID, forum.ForumID, newTitle, urlName);
				_topicRepository.MarkTopicForIndexing(topic.TopicID);
				_forumService.UpdateCounts(forum);
				_forumService.UpdateLast(forum);
				var oldForum = _forumService.Get(oldTopic.ForumID);
				_forumService.UpdateCounts(oldForum);
				_forumService.UpdateLast(oldForum);
			}
			else
				throw new InvalidOperationException("User must be Moderator to update topic title or move topic.");
		}
开发者ID:andyliyuze,项目名称:POPForums,代码行数:22,代码来源:TopicService.cs

示例3: HardDeleteTopic

		public void HardDeleteTopic(Topic topic, User user)
		{
			if (user.IsInRole(PermanentRoles.Admin))
			{
				_moderationLogService.LogTopic(user, ModerationType.TopicDeletePermanently, topic, null);
				_searchRepository.DeleteAllIndexedWordsForTopic(topic.TopicID);
				_topicRepository.HardDeleteTopic(topic.TopicID);
				var forum = _forumService.Get(topic.ForumID);
				_forumService.UpdateCounts(forum);
				_forumService.UpdateLast(forum);
			}
			else
				throw new InvalidOperationException("User must be Admin to hard delete topic.");
		}
开发者ID:andyliyuze,项目名称:POPForums,代码行数:14,代码来源:TopicService.cs

示例4: UnpinTopic

		public void UnpinTopic(Topic topic, User user)
		{
			if (user.IsInRole(PermanentRoles.Moderator))
			{
				_moderationLogService.LogTopic(user, ModerationType.TopicUnpin, topic, null);
				_topicRepository.UnpinTopic(topic.TopicID);
			}
			else
				throw new InvalidOperationException("User must be Moderator to unpin topic.");
		}
开发者ID:andyliyuze,项目名称:POPForums,代码行数:10,代码来源:TopicService.cs

示例5: Undelete

		public void Undelete(Post post, User user)
		{
			if (user.IsInRole(PermanentRoles.Moderator))
			{
				_moderationLogService.LogPost(user, ModerationType.PostUndelete, post, String.Empty, String.Empty);
				post.IsDeleted = false;
				post.LastEditTime = DateTime.UtcNow;
				post.LastEditName = user.Name;
				post.IsEdited = true;
				_postRepository.Update(post);
				var topic = _topicService.Get(post.TopicID);
				_topicService.RecalculateReplyCount(topic);
				_topicService.UpdateLast(topic);
				var forum = _forumService.Get(topic.ForumID);
				_forumService.UpdateCounts(forum);
				_forumService.UpdateLast(forum);
			}
			else
				throw new InvalidOperationException("User must be Moderator to undelete post.");
		}
开发者ID:andyliyuze,项目名称:POPForums,代码行数:20,代码来源:PostService.cs

示例6: GetPermissionContext

		public ForumPermissionContext GetPermissionContext(Forum forum, User user, Topic topic)
		{
			var context = new ForumPermissionContext { DenialReason = String.Empty };
			var viewRestrictionRoles = _forumRepository.GetForumViewRoles(forum.ForumID);
			var postRestrictionRoles = _forumRepository.GetForumPostRoles(forum.ForumID);

			// view
			if (viewRestrictionRoles.Count == 0)
				context.UserCanView = true;
			else
			{
				context.UserCanView = false;
				if (user != null && viewRestrictionRoles.Where(user.IsInRole).Count() > 0)
					context.UserCanView = true;
			}

			// post
			if (user == null || !context.UserCanView)
			{
				context.UserCanPost = false;
				context.DenialReason = Resources.LoginToPost;
			}
			else
				if (!user.IsApproved)
				{
					context.DenialReason += "You can't post until you have verified your account. ";
					context.UserCanPost = false;
				}
				else
				{
					if (postRestrictionRoles.Count == 0)
						context.UserCanPost = true;
					else
					{
						if (postRestrictionRoles.Where(user.IsInRole).Count() > 0)
							context.UserCanPost = true;
						else
						{
							context.DenialReason += Resources.ForumNoPost + ". ";
							context.UserCanPost = false;
						}
					}
				}

			if (topic != null && topic.IsClosed)
			{
				context.UserCanPost = false;
				context.DenialReason += Resources.Closed + ". ";
			}

			if (topic != null && topic.IsDeleted)
			{
				if (user == null || !user.IsInRole(PermanentRoles.Moderator))
					context.UserCanView = false;
				context.DenialReason += "Topic is deleted. ";
			}

			if (forum.IsArchived)
			{
				context.UserCanPost = false;
				context.DenialReason += Resources.Archived + ". ";
			}
			
			// moderate
			context.UserCanModerate = false;
			if (user != null && (user.IsInRole(PermanentRoles.Admin) || user.IsInRole(PermanentRoles.Moderator)))
				context.UserCanModerate = true;

			return context;
		}
开发者ID:andyliyuze,项目名称:POPForums,代码行数:70,代码来源:ForumService.cs

示例7: GetFirstUnreadPost

		public Post GetFirstUnreadPost(User user, Topic topic)
		{
			if (topic == null)
				throw new ArgumentException("Can't use a null topic.", "topic");
			var includeDeleted = false;
			if (user != null && user.IsInRole(PermanentRoles.Moderator))
				includeDeleted = true;
			var postIDs = _postRepository.GetPostIDsWithTimes(topic.TopicID, includeDeleted).Select(d => new { PostID = d.Key, PostTime = d.Value }).ToList();
			if (user == null)
				return _postRepository.Get(postIDs[0].PostID);
			var lastRead = _lastReadRepository.GetLastReadTimeForTopic(user.UserID, topic.TopicID);
			if (!lastRead.HasValue)
				lastRead = _lastReadRepository.GetLastReadTimesForForum(user.UserID, topic.ForumID);
			if (!lastRead.HasValue || !postIDs.Any(p => p.PostTime > lastRead.Value))
				return _postRepository.Get(postIDs[0].PostID);
			var firstNew = postIDs.First(p => p.PostTime > lastRead.Value);
			return _postRepository.Get(firstNew.PostID);
		}
开发者ID:andyliyuze,项目名称:POPForums,代码行数:18,代码来源:LastReadService.cs


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