/// <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 reportService = new ReportService(); var report = reportService.Get(int.Parse(hfReportId.Value)); if (report != null) { string errorMessage; if (!reportService.CanDelete(report, out errorMessage)) { ShowReadonlyDetails(report); mdDeleteWarning.Show(errorMessage, ModalAlertType.Information); } else { categoryId = report.CategoryId; reportService.Delete(report, CurrentPersonId); reportService.Save(report, 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> /// Shows the detail. /// </summary> /// <param name="itemKey">The item key.</param> /// <param name="itemKeyValue">The item key value.</param> /// <param name="parentCategoryId">The parent category id.</param> public void ShowDetail(string itemKey, int itemKeyValue, int?parentCategoryId) { pnlDetails.Visible = false; if (!itemKey.Equals("ReportId")) { return; } var reportService = new ReportService(); Report report = null; if (!itemKeyValue.Equals(0)) { report = reportService.Get(itemKeyValue); } else { report = new Report { Id = 0, IsSystem = false, CategoryId = parentCategoryId }; } if (report == null || !report.IsAuthorized("View", CurrentPerson)) { return; } pnlDetails.Visible = true; hfReportId.Value = report.Id.ToString(); // render UI based on Authorized and IsSystem bool readOnly = false; nbEditModeMessage.Text = string.Empty; if (!report.IsAuthorized("Edit", CurrentPerson)) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(Report.FriendlyTypeName); } if (report.IsSystem) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem(Report.FriendlyTypeName); } btnSecurity.Visible = report.IsAuthorized("Administrate", CurrentPerson); btnSecurity.Title = report.Name; btnSecurity.EntityId = report.Id; if (readOnly) { btnEdit.Visible = false; btnDelete.Visible = false; ShowReadonlyDetails(report); } else { btnEdit.Visible = true; string errorMessage = string.Empty; btnDelete.Visible = reportService.CanDelete(report, out errorMessage); if (report.Id > 0) { ShowReadonlyDetails(report); } else { ShowEditDetails(report); } } }