/// <summary> /// Handles the Delete event of the gList 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 gList_Delete(object sender, RowEventArgs e) { var rockContext = new RockContext(); var service = new NoteWatchService(rockContext); var noteWatch = service.Get(e.RowKeyId); if (noteWatch != null) { string errorMessage; if (!service.CanDelete(noteWatch, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } service.Delete(noteWatch); rockContext.SaveChanges(); } BindGrid(); }
/// <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) { NoteWatch noteWatch; var rockContext = new RockContext(); var noteWatchService = new NoteWatchService(rockContext); var noteWatchId = hfNoteWatchId.Value.AsInteger(); if (noteWatchId == 0) { noteWatch = new NoteWatch(); noteWatchService.Add(noteWatch); } else { noteWatch = noteWatchService.Get(noteWatchId); } noteWatch.NoteTypeId = ddlNoteType.SelectedValue.AsIntegerOrNull(); noteWatch.EntityTypeId = etpEntityType.SelectedEntityTypeId; if (noteWatch.EntityTypeId.HasValue) { if (noteWatch.EntityTypeId.Value == EntityTypeCache.GetId <Rock.Model.Person>()) { noteWatch.EntityId = ppWatchedPerson.PersonId; } else if (noteWatch.EntityTypeId.Value == EntityTypeCache.GetId <Rock.Model.Group>()) { noteWatch.EntityId = gpWatchedGroup.GroupId; } else { noteWatch.EntityId = nbWatchedEntityId.Text.AsIntegerOrNull(); } } noteWatch.WatcherPersonAliasId = ppWatcherPerson.PersonAliasId; noteWatch.WatcherGroupId = gpWatcherGroup.GroupId; noteWatch.IsWatching = cbIsWatching.Checked; noteWatch.AllowOverride = cbAllowOverride.Checked; // see if the Watcher parameters are valid if (!noteWatch.IsValidWatcher) { nbWatcherMustBeSelectWarning.Visible = true; return; } // see if the Watch filters parameters are valid if (!noteWatch.IsValidWatchFilter) { nbWatchFilterMustBeSeletedWarning.Visible = true; return; } if (!noteWatch.IsValid) { return; } // See if there is a matching filter that doesn't allow overrides if (noteWatch.IsWatching == false) { if (!noteWatch.IsAbleToUnWatch(rockContext)) { var nonOverridableNoteWatch = noteWatch.GetNonOverridableNoteWatches(rockContext).FirstOrDefault(); if (nonOverridableNoteWatch != null) { string otherNoteWatchLink; if (nonOverridableNoteWatch.IsAuthorized(Rock.Security.Authorization.VIEW, this.CurrentPerson)) { var otherNoteWatchWatchPageReference = new Rock.Web.PageReference(this.CurrentPageReference); otherNoteWatchWatchPageReference.QueryString = new System.Collections.Specialized.NameValueCollection(otherNoteWatchWatchPageReference.QueryString); otherNoteWatchWatchPageReference.QueryString["NoteWatchId"] = nonOverridableNoteWatch.Id.ToString(); otherNoteWatchLink = string.Format("<a href='{0}'>note watch</a>", otherNoteWatchWatchPageReference.BuildUrl()); } else { otherNoteWatchLink = "note watch"; } nbUnableToOverride.Text = string.Format( "Unable to set Watching to false. This would override another {0} that doesn't allow overrides.", otherNoteWatchLink); nbUnableToOverride.Visible = true; return; } } } // see if the NoteType allows following if (noteWatch.NoteTypeId.HasValue) { var noteTypeCache = NoteTypeCache.Get(noteWatch.NoteTypeId.Value); if (noteTypeCache != null) { if (noteTypeCache.AllowsWatching == false) { nbNoteTypeWarning.Visible = true; return; } } } rockContext.SaveChanges(); NavigateToNoteWatchParentPage(); }