/// <summary> /// Handles the Delete event of the gSectionList control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gSectionList_Delete(object sender, RowEventArgs e) { var rockContext = new RockContext(); var personalLinkSectionService = new PersonalLinkSectionService(rockContext); var personalLinkSection = personalLinkSectionService.Get(e.RowKeyId); if (personalLinkSection != null) { string errorMessage; if (!personalLinkSectionService.CanDelete(personalLinkSection, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } personalLinkSectionService.Delete(personalLinkSection); rockContext.SaveChanges(); } BindGrid(); }
/// <summary> /// Shows the detail. /// </summary> /// <param name="personalLinkSectionId">The personal link section element identifier.</param> public void ShowDetail(int personalLinkSectionId) { var rockContext = new RockContext(); var personalLinkSectionService = new PersonalLinkSectionService(rockContext); PersonalLinkSection personalLinkSection = null; bool isNew = false; if (!personalLinkSectionId.Equals(0)) { personalLinkSection = personalLinkSectionService.Get(personalLinkSectionId); } if (personalLinkSection == null) { personalLinkSection = new PersonalLinkSection { Id = 0 }; isNew = true; } hfPersonalLinkSectionId.SetValue(personalLinkSection.Id); if (personalLinkSection != null && personalLinkSection.IsAuthorized(Authorization.VIEW, CurrentPerson)) { hfPersonalLinkSectionId.Value = personalLinkSection.Id.ToString(); bool readOnly = false; bool editAllowed = isNew || personalLinkSection.IsAuthorized(Authorization.EDIT, CurrentPerson); nbEditModeMessage.Text = string.Empty; if (!editAllowed) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(ContentChannel.FriendlyTypeName); } if (readOnly) { btnEdit.Visible = false; ShowReadonlyDetails(personalLinkSection); } else { btnEdit.Visible = true; if (personalLinkSection.Id > 0) { ShowReadonlyDetails(personalLinkSection); } else { ShowEditDetails(personalLinkSection); } } btnSecurity.Visible = personalLinkSection.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson); btnSecurity.Title = personalLinkSection.Name; btnSecurity.EntityId = personalLinkSection.Id; btnSave.Visible = !readOnly; } else { nbEditModeMessage.Text = EditModeMessage.NotAuthorizedToView(ContentChannel.FriendlyTypeName); pnlEditDetails.Visible = false; pnlViewDetails.Visible = false; this.HideSecondaryBlocks(true); } }
/// <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); }