/// <summary> /// Handles the Delete event of the gLinkList 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 gLinkList_Delete(object sender, RowEventArgs e) { var rockContext = new RockContext(); var personalLinkService = new PersonalLinkService(rockContext); var personalLink = personalLinkService.Get(e.RowKeyId); if (personalLink != null) { string errorMessage; if (!personalLink.IsAuthorized(Authorization.EDIT, CurrentPerson)) { mdGridWarning.Show("You are not authorized to delete this link", ModalAlertType.Information); return; } if (!personalLinkService.CanDelete(personalLink, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } personalLinkService.Delete(personalLink); rockContext.SaveChanges(); } BindGrid(); }
/// <summary> /// Handles the SaveClick event of the mdAddPersonalLink 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 mdAddPersonalLink_SaveClick(object sender, EventArgs e) { var rockContext = new RockContext(); var personalLinkService = new PersonalLinkService(rockContext); PersonalLink personalLink = null; if (hfPersonalLinkId.Value.AsInteger() != 0) { personalLink = personalLinkService.Get(hfPersonalLinkId.Value.AsInteger()); } else { personalLink = new PersonalLink { SectionId = _personalLinkSection.Id }; // add the new link to the bottom of the list for that section var lastLinkOrder = personalLinkService.Queryable().Where(a => a.SectionId == _personalLinkSection.Id).Max(a => ( int? )a.Order) ?? 0; personalLink.Order = lastLinkOrder + 1; personalLinkService.Add(personalLink); } if (_personalLinkSection?.IsShared == true) { personalLink.PersonAliasId = null; } else { personalLink.PersonAliasId = CurrentPersonAliasId.Value; } personalLink.Name = tbName.Text; personalLink.Url = urlLink.Text; rockContext.SaveChanges(); mdAddPersonalLink.Hide(); BindGrid(); }