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


C# IPrincipal.HasAccessFor方法代码示例

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


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

示例1: GetVisibleUnits

		public List<string> GetVisibleUnits(string courseId, IPrincipal user)
		{
			var canSeeEverything = user.HasAccessFor(courseId, CourseRole.Tester);
			if (canSeeEverything)
				return courseManager.GetCourse(courseId).Slides.Select(s => s.Info.UnitName).Distinct().ToList();
			return db.Units.Where(u => u.CourseId == courseId && u.PublishTime <= DateTime.Now).Select(u => u.UnitName).ToList();
		}
开发者ID:andgein,项目名称:uLearn,代码行数:7,代码来源:UnitsRepo.cs

示例2: CanAddCommentHere

		private bool CanAddCommentHere(IPrincipal user, string courseId, bool isReply)
		{
			if (!User.Identity.IsAuthenticated)
				return false;

			var commentsPolicy = commentsRepo.GetCommentsPolicy(courseId);
			var isInstructor = user.HasAccessFor(courseId, CourseRole.Instructor);

			if (!isInstructor && !commentsPolicy.IsCommentsEnabled)
				return false;

			if (isReply && !isInstructor && commentsPolicy.OnlyInstructorsCanReply)
				return false;

			return true;
		}
开发者ID:kontur-edu,项目名称:uLearn,代码行数:16,代码来源:CommentsController.cs

示例3: AddComment

		public async Task<Comment> AddComment(IPrincipal author, string courseId, Guid slideId, int parentCommentId, string commentText)
		{
			var commentsPolicy = GetCommentsPolicy(courseId);
			var isInstructor = author.HasAccessFor(courseId, CourseRole.Instructor);
			var isApproved = commentsPolicy.ModerationPolicy == CommentModerationPolicy.Postmoderation || isInstructor;

			/* Instructors' replies are automaticly correct */
			var isReply = parentCommentId != -1;
			var isCorrectAnswer = isReply && isInstructor;

			var comment = db.Comments.Create();
			comment.AuthorId = author.Identity.GetUserId();
			comment.CourseId = courseId;
			comment.SlideId = slideId;
			comment.ParentCommentId = parentCommentId;
			comment.Text = commentText;
			comment.IsApproved = isApproved;
			comment.IsCorrectAnswer = isCorrectAnswer;
			comment.PublishTime = DateTime.Now;
			db.Comments.Add(comment);
			await db.SaveChangesAsync();

			return db.Comments.Find(comment.Id);
		}
开发者ID:kontur-edu,项目名称:uLearn,代码行数:24,代码来源:CommentsRepo.cs

示例4: CanAddCommentNow

		private bool CanAddCommentNow(IPrincipal user, string courseId)
		{
			// Instructors have unlimited comments
			if (user.HasAccessFor(courseId, CourseRole.Instructor))
				return true;

			var commentsPolicy = commentsRepo.GetCommentsPolicy(courseId);
			return ! commentsRepo.IsUserAddedMaxCommentsInLastTime(user.Identity.GetUserId(),
				commentsPolicy.MaxCommentsCountInLastTime,
				commentsPolicy.LastTimeForMaxCommentsLimit);
		}
开发者ID:kontur-edu,项目名称:uLearn,代码行数:11,代码来源:CommentsController.cs

示例5: CanEditAndDeleteComment

		private bool CanEditAndDeleteComment(IPrincipal user, Comment comment)
		{
			return user.HasAccessFor(comment.CourseId, CourseRole.Instructor) ||
					user.Identity.GetUserId() == comment.AuthorId;
		}
开发者ID:kontur-edu,项目名称:uLearn,代码行数:5,代码来源:CommentsController.cs

示例6: CanUserSeeAllCourseGroups

		public bool CanUserSeeAllCourseGroups(IPrincipal user, string courseId)
		{
			return user.HasAccessFor(courseId, CourseRole.CourseAdmin);
		}
开发者ID:kontur-edu,项目名称:uLearn,代码行数:4,代码来源:GroupsRepo.cs

示例7: GetAvailableForUserGroups

		public List<Group> GetAvailableForUserGroups(string courseId, IPrincipal user)
		{
			if (!user.HasAccessFor(courseId, CourseRole.Instructor))
				return new List<Group>();

			IEnumerable<Group> groups;
			var userId = user.Identity.GetUserId();

			/* Course admins can see all groups */
			if (CanUserSeeAllCourseGroups(user, courseId))
				groups = GetGroups(courseId);
			else
				/* Other instructor can see only public or own groups */
				groups = db.Groups.Where(g => g.CourseId == courseId && !g.IsDeleted && (g.OwnerId == userId || g.IsPublic));
			
			return groups
				.OrderBy(g => g.OwnerId != userId)
				.ThenBy(g => g.Name)
				.ToList();
		}
开发者ID:kontur-edu,项目名称:uLearn,代码行数:20,代码来源:GroupsRepo.cs

示例8: IsGroupAvailableForUser

		public bool IsGroupAvailableForUser(int groupId, IPrincipal user)
		{
			var group = FindGroupById(groupId);
			/* Course admins can see all groups */
			if (CanUserSeeAllCourseGroups(user, group.CourseId))
				return true;

			if (!user.HasAccessFor(group.CourseId, CourseRole.Instructor))
				return false;

			var userId = user.Identity.GetUserId();
			return !group.IsDeleted && (group.OwnerId == userId || group.IsPublic);
		}
开发者ID:kontur-edu,项目名称:uLearn,代码行数:13,代码来源:GroupsRepo.cs


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