當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。