/// <summary> /// Handles the Click event of the btnDelete 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 btnDelete_Click(object sender, EventArgs e) { int?categoryId = null; var dataViewService = new DataViewService(); var dataView = dataViewService.Get(int.Parse(hfDataViewId.Value)); if (dataView != null) { string errorMessage; if (!dataViewService.CanDelete(dataView, out errorMessage)) { ShowReadonlyDetails(dataView); mdDeleteWarning.Show(errorMessage, ModalAlertType.Information); } else { categoryId = dataView.CategoryId; dataViewService.Delete(dataView, CurrentPersonId); dataViewService.Save(dataView, CurrentPersonId); // reload page, selecting the deleted data view's parent var qryParams = new Dictionary <string, string>(); if (categoryId != null) { qryParams["CategoryId"] = categoryId.ToString(); } NavigateToPage(this.CurrentPage.Guid, qryParams); } } }
/// <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) { DataView dataView = null; using (new UnitOfWorkScope()) { DataViewService service = new DataViewService(); int dataViewId = int.Parse(hfDataViewId.Value); int?dataViewFilterId = null; if (dataViewId == 0) { dataView = new DataView(); dataView.IsSystem = false; } else { dataView = service.Get(dataViewId); dataViewFilterId = dataView.DataViewFilterId; } dataView.Name = tbName.Text; dataView.Description = tbDescription.Text; dataView.TransformEntityTypeId = ddlTransform.SelectedValueAsInt(); dataView.EntityTypeId = ddlEntityType.SelectedValueAsInt(); dataView.CategoryId = cpCategory.SelectedValueAsInt(); dataView.DataViewFilter = GetFilterControl(); if (!Page.IsValid) { return; } if (!dataView.IsValid) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction(() => { if (dataView.Id.Equals(0)) { service.Add(dataView, CurrentPersonId); } service.Save(dataView, CurrentPersonId); // Delete old report filter if (dataViewFilterId.HasValue) { DataViewFilterService dataViewFilterService = new DataViewFilterService(); DataViewFilter dataViewFilter = dataViewFilterService.Get(dataViewFilterId.Value); DeleteDataViewFilter(dataViewFilter, dataViewFilterService); dataViewFilterService.Save(dataViewFilter, CurrentPersonId); } }); } var qryParams = new Dictionary <string, string>(); qryParams["DataViewId"] = dataView.Id.ToString(); NavigateToPage(this.CurrentPage.Guid, qryParams); }