/// <summary> /// Save the section. /// </summary> private int SaveSection(string sectionName) { var rockContext = new RockContext(); var personalLinkSectionService = new PersonalLinkSectionService(rockContext); var personalLinkSection = new PersonalLinkSection() { Id = 0, IsShared = false, PersonAliasId = CurrentPersonAliasId.Value, Name = sectionName }; personalLinkSectionService.Add(personalLinkSection); rockContext.SaveChanges(); personalLinkSection.MakePrivate(Authorization.VIEW, CurrentPerson, rockContext); personalLinkSection.MakePrivate(Authorization.EDIT, CurrentPerson, rockContext); personalLinkSection.MakePrivate(Authorization.ADMINISTRATE, CurrentPerson, rockContext); return(personalLinkSection.Id); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } var rockContext = new RockContext(); var personalLinkSectionService = new PersonalLinkSectionService(rockContext); var personalLinkSectionId = hfPersonalLinkSectionId.Value.AsIntegerOrNull(); PersonalLinkSection personalLinkSection = null; if (personalLinkSectionId.HasValue) { personalLinkSection = personalLinkSectionService.Get(personalLinkSectionId.Value); } var isNew = personalLinkSection == null; if (isNew) { var isShared = GetAttributeValue(AttributeKey.SharedSection).AsBoolean(); personalLinkSection = new PersonalLinkSection() { Id = 0, IsShared = isShared }; if (!isShared) { personalLinkSection.PersonAliasId = CurrentPersonAliasId.Value; } personalLinkSectionService.Add(personalLinkSection); } personalLinkSection.Name = tbName.Text; rockContext.SaveChanges(); personalLinkSection = personalLinkSectionService.Get(personalLinkSection.Id); if (personalLinkSection != null) { if (personalLinkSection.IsShared) { var groupService = new GroupService(rockContext); var communicationAdministrators = groupService.Get(Rock.SystemGuid.Group.GROUP_COMMUNICATION_ADMINISTRATORS.AsGuid()); if (communicationAdministrators != null) { personalLinkSection.AllowSecurityRole(Authorization.VIEW, communicationAdministrators, rockContext); personalLinkSection.AllowSecurityRole(Authorization.EDIT, communicationAdministrators, rockContext); personalLinkSection.AllowSecurityRole(Authorization.ADMINISTRATE, communicationAdministrators, rockContext); } var webAdministrators = groupService.Get(Rock.SystemGuid.Group.GROUP_WEB_ADMINISTRATORS.AsGuid()); if (webAdministrators != null) { personalLinkSection.AllowSecurityRole(Authorization.VIEW, webAdministrators, rockContext); personalLinkSection.AllowSecurityRole(Authorization.EDIT, webAdministrators, rockContext); personalLinkSection.AllowSecurityRole(Authorization.ADMINISTRATE, webAdministrators, rockContext); } var rockAdministrators = groupService.Get(Rock.SystemGuid.Group.GROUP_ADMINISTRATORS.AsGuid()); if (rockAdministrators != null) { personalLinkSection.AllowSecurityRole(Authorization.VIEW, rockAdministrators, rockContext); personalLinkSection.AllowSecurityRole(Authorization.EDIT, rockAdministrators, rockContext); personalLinkSection.AllowSecurityRole(Authorization.ADMINISTRATE, rockAdministrators, rockContext); } } else { personalLinkSection.MakePrivate(Authorization.VIEW, CurrentPerson); personalLinkSection.MakePrivate(Authorization.EDIT, CurrentPerson, rockContext); personalLinkSection.MakePrivate(Authorization.ADMINISTRATE, CurrentPerson, rockContext); } } var pageReference = RockPage.PageReference; pageReference.Parameters.AddOrReplace(PageParameterKey.SectionId, personalLinkSection.Id.ToString()); Response.Redirect(pageReference.BuildUrl(), false); }