/// <summary>
		/// Executes before the action is executed.
		/// </summary>
		protected override async Task InitializeAsync()
		{
			await base.InitializeAsync();

			Section = await SectionService.GetSectionAsync(ClassroomName, SectionName);
			SectionRole = GetSectionRole(User, Section);

			ViewBag.Section = Section;
			ViewBag.SectionRole = SectionRole;
		}
Beispiel #2
0
        /// <summary>
        /// Executes before the action is executed.
        /// </summary>
        protected override async Task InitializeAsync()
        {
            await base.InitializeAsync();

            Section = await SectionService.GetSectionAsync(ClassroomName, SectionName);

            SectionRole = GetSectionRole(User, Section);

            ViewBag.Section     = Section;
            ViewBag.SectionRole = SectionRole;
        }
Beispiel #3
0
        /// <summary>
        /// Ensures a section membership exists for the given user and role.
        /// The caller is responsible for saving changes.
        /// </summary>
        private async Task <SectionMembership> EnsureSectionMembershipAsync(
            User user,
            Section section,
            SectionRole role)
        {
            var classroomMembership = await EnsureClassroomMembershipAsync(
                user,
                section.Classroom,
                ClassroomRole.General);

            if (classroomMembership.SectionMemberships == null)
            {
                classroomMembership.SectionMemberships = new List <SectionMembership>();
            }

            var sectionMembership = classroomMembership.SectionMemberships
                                    .SingleOrDefault(m => m.SectionId == section.Id);

            if (sectionMembership == null)
            {
                sectionMembership = new SectionMembership()
                {
                    ClassroomMembershipId = classroomMembership.Id,
                    ClassroomMembership   = classroomMembership,
                    SectionId             = section.Id,
                    Section = section,
                    Role    = role
                };

                classroomMembership.SectionMemberships.Add(sectionMembership);
            }
            else if (role > sectionMembership.Role)
            {
                sectionMembership.Role = role;
            }

            return(sectionMembership);
        }
Beispiel #4
0
		/// <summary>
		/// Ensures a section membership exists for the given user and role.
		/// The caller is responsible for saving changes.
		/// </summary>
		private async Task<SectionMembership> EnsureSectionMembershipAsync(
			User user,
			Section section,
			SectionRole role)
		{
			var classroomMembership = await EnsureClassroomMembershipAsync(
				user,
				section.Classroom,
				ClassroomRole.General);

			if (classroomMembership.SectionMemberships == null)
			{
				classroomMembership.SectionMemberships = new List<SectionMembership>();
			}

			var sectionMembership = classroomMembership.SectionMemberships
				.SingleOrDefault(m => m.SectionId == section.Id);

			if (sectionMembership == null)
			{
				sectionMembership = new SectionMembership()
				{
					ClassroomMembershipId = classroomMembership.Id,
					ClassroomMembership = classroomMembership,
					SectionId = section.Id,
					Section = section,
					Role = role
				};

				classroomMembership.SectionMemberships.Add(sectionMembership);
			}
			else if (role > sectionMembership.Role)
			{
				sectionMembership.Role = role;
			}

			return sectionMembership;
		}
Beispiel #5
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public SectionAuthorizationAttribute(SectionRole sectionRoleRequired)
     : base(ClassroomRole.General)
 {
     SectionRoleRequired = sectionRoleRequired;
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 public SectionAuthorizationAttribute(SectionRole sectionRoleRequired)
     : base(ClassroomRole.General)
 {
     SectionRoleRequired = sectionRoleRequired;
 }