/// <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; }
/// <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; }
/// <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); }
/// <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; }
/// <summary> /// Constructor. /// </summary> public SectionAuthorizationAttribute(SectionRole sectionRoleRequired) : base(ClassroomRole.General) { SectionRoleRequired = sectionRoleRequired; }
/// <summary> /// Constructor. /// </summary> public SectionAuthorizationAttribute(SectionRole sectionRoleRequired) : base(ClassroomRole.General) { SectionRoleRequired = sectionRoleRequired; }