Ejemplo n.º 1
0
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        setupJoinRenewLink();

        if (!string.IsNullOrWhiteSpace(MembershipId))
        {
            liViewMembership.Visible = true;
            //liViewAllMemberships.Visible = true;

            hlViewMembership.NavigateUrl += "?contextID=" + MembershipId;
        }

        liSearchMembershipDirectory.Visible = isMembershipDirectoryAvailable();

        if (ChapterMembership != null)
        {
            //Bind the view chapter links starting with chapters the current entity is a member of - get distinct rows with the ToTable method
            //Filter out the primary chapter because the link is already displayed
            ChapterMembership.RowFilter     = buildChapterMembershipFilter();
            rptChapterMembership.DataSource = ChapterMembership.ToTable(true, new[] { "Chapter.ID", "Chapter.Name" });
            rptChapterMembership.DataBind();
        }

        if (ChapterLeadership != null)
        {
            //Now filter the ones we just databound with the chapter membership from the chapter leadership
            ChapterLeadership.RowFilter     = buildChapterLeadershipFilter();
            rptChapterLeadership.DataSource = ChapterLeadership.ToTable(true, new[] { "Chapter.ID", "Chapter.Name" });
            rptChapterLeadership.DataBind();
        }

        if (SectionMembership != null)
        {
            //Bind the view section links starting with chapters the current entity is a member of - get distinct rows with the ToTable method
            rptSectionMembership.DataSource = SectionMembership.ToTable(true, new[] { "Section.ID", "Section.Name" });
            rptSectionMembership.DataBind();
        }

        if (SectionLeadership != null)
        {
            //Now filter the ones we just databound with the section membership from the section leadership and bind to distinct rows with the ToTable method
            SectionLeadership.RowFilter     = buildSectionLeadershipFilter();
            rptSectionLeadership.DataSource = SectionLeadership.ToTable(true, new[] { "Section.ID", "Section.Name" });
            rptSectionLeadership.DataBind();
        }
    }
Ejemplo n.º 2
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);
        }