示例#1
0
        /// <summary>
        /// Ensures a classroom membership exists for the given user and role.
        /// The caller is responsible for saving changes.
        /// </summary>
        private async Task <ClassroomMembership> EnsureClassroomMembershipAsync(
            User user,
            Classroom classroom,
            ClassroomRole role)
        {
            var classroomMembership = user?.ClassroomMemberships
                                      ?.SingleOrDefault(m => m.ClassroomId == classroom.Id);

            if (user.ClassroomMemberships == null)
            {
                user.ClassroomMemberships = new List <ClassroomMembership>();
            }

            if (classroomMembership == null)
            {
                classroomMembership = new ClassroomMembership()
                {
                    ClassroomId          = classroom.Id,
                    Classroom            = classroom,
                    InGitHubOrganization = false,
                    GitHubTeam           = await GetNewGitHubTeamNameAsync(classroom, user),
                    Role = role
                };

                user.ClassroomMemberships.Add(classroomMembership);
            }
            else if (role > classroomMembership.Role)
            {
                classroomMembership.Role = role;
            }

            return(classroomMembership);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 public ClassroomAuthorizationAttribute(ClassroomRole classroomRoleRequired)
     : base(RequiredAccess.Registered)
 {
     ClassroomRoleRequired = classroomRoleRequired;
 }
示例#3
0
		/// <summary>
		/// Ensures a classroom membership exists for the given user and role.
		/// The caller is responsible for saving changes.
		/// </summary>
		private async Task<ClassroomMembership> EnsureClassroomMembershipAsync(
			User user,
			Classroom classroom,
			ClassroomRole role)
		{
			var classroomMembership = user?.ClassroomMemberships
				?.SingleOrDefault(m => m.ClassroomId == classroom.Id);

			if (user.ClassroomMemberships == null)
			{
				user.ClassroomMemberships = new List<ClassroomMembership>();
			}

			if (classroomMembership == null)
			{
				classroomMembership = new ClassroomMembership()
				{
					ClassroomId = classroom.Id,
					Classroom = classroom,
					InGitHubOrganization = false,
					GitHubTeam = await GetNewGitHubTeamNameAsync(classroom, user),
					Role = role
				};

				user.ClassroomMemberships.Add(classroomMembership);
			}
			else if (role > classroomMembership.Role)
			{
				classroomMembership.Role = role;
			}

			return classroomMembership;
		}
 /// <summary>
 /// Constructor.
 /// </summary>
 public ClassroomAuthorizationAttribute(ClassroomRole classroomRoleRequired)
     : base(RequiredAccess.Registered)
 {
     ClassroomRoleRequired = classroomRoleRequired;
 }