public ActionResult CustomReportSql(string report) { try { var m = new CustomReportsModel(DbUtil.Db, report); return Content($"<pre style='font-family:monospace'>{m.Sql()}\n</pre>"); } catch (Exception ex) { return Message(ex.Message); } }
public ActionResult AddReport(string report, string url, string type) { var m = new CustomReportsModel(DbUtil.Db); try { var dest = m.AddReport(report, url, type); return PageMessage($"Report Added to {dest}", "Report Added", "success"); } catch (Exception ex) { return PageMessage(ex.Message); } }
public JsonResult DeleteCustomReport(string report) { if (string.IsNullOrEmpty(report)) return new JsonResult {Data = "Report name is required."}; var m = new CustomReportsModel(DbUtil.Db); m.DeleteReport(report); return new JsonResult {Data = "success"}; }
public ActionResult CustomReportExcel(Guid id, string report) { var m = new CustomReportsModel(DbUtil.Db, report, id); return m.Result(); }
public ActionResult CustomReport(Guid id, string report) { var m = new CustomReportsModel(DbUtil.Db, report, id); return View(m); }
public ActionResult EditCustomReport(CustomReportViewModel vm) { if (!vm.Columns.Any(c => c.IsSelected)) ModelState.AddModelError("Columns", "At least one column must be selected."); if (ModelState.IsValid) { vm.ReportName = SecurityElement.Escape(vm.ReportName.Trim()); try { var m = new CustomReportsModel(DbUtil.Db, vm.OrgId); m.SaveReport(vm.OriginalReportName, vm.ReportName, vm.Columns.Where(c => c.IsSelected), vm.RestrictToThisOrg); TempDataSaved = true; } catch (Exception) { ModelState.AddModelError("ReportName", "A report by this name already exists."); } } if (ModelState.IsValid) return Redirect(CustomReportsModel.GetEditUrl(vm.ReportName, vm.QueryId, vm.OrgId)); TempDataModelState = ModelState; TempDataCustomReport = vm; return Redirect(CustomReportsModel.GetEditUrl(vm.OriginalReportName, vm.QueryId, vm.OrgId)); }
public ActionResult EditCustomReport(int? orgId, string report, Guid queryId) { var modelstate = TempDataModelState; if (modelstate != null) ModelState.Merge(modelstate); var m = new CustomReportsModel(DbUtil.Db, report, queryId, orgId); var vm = m.EditCustomReport(TempDataCustomReport, TempDataSaved); return View(vm); }
private static IEnumerable<CustomReportColumn> GetAllStandardColumns(CustomReportsModel model) { var reportXml = model.StandardColumns(); return MapXmlToCustomReportColumn(reportXml); }
public ActionResult EditCustomReport(CustomReportViewModel viewModel) { if (!viewModel.Columns.Any(c => c.IsSelected)) ModelState.AddModelError("Columns", "At least one column must be selected."); if (ModelState.IsValid) { viewModel.ReportName = SecurityElement.Escape(viewModel.ReportName.Trim()); var m = new CustomReportsModel(DbUtil.Db, viewModel.OrgId); var result = m.SaveReport(viewModel.OriginalReportName, viewModel.ReportName, viewModel.Columns.Where(c => c.IsSelected), viewModel.RestrictToThisOrg); switch (result) { case CustomReportsModel.SaveReportStatus.ReportAlreadyExists: ModelState.AddModelError("ReportName", "A report by this name already exists."); break; default: TempData[TempDataSuccessfulSaved] = true; break; } } if (!ModelState.IsValid) { TempData[TempDataModelStateKey] = ModelState; TempData[TempDataCustomReportKey] = viewModel; return RedirectToAction("EditCustomReport", new { reportName = viewModel.OriginalReportName, orgId = viewModel.OrgId, queryId = viewModel.QueryId }); } return RedirectToAction("EditCustomReport", new { reportName = viewModel.ReportName, orgId = viewModel.OrgId, queryId = viewModel.QueryId }); }
public ActionResult EditCustomReport(int? orgId, string reportName, Guid queryId) { CustomReportViewModel originalReportViewModel = null; if (TempData[TempDataModelStateKey] != null) { ModelState.Merge((ModelStateDictionary) TempData[TempDataModelStateKey]); originalReportViewModel = TempData[TempDataCustomReportKey] as CustomReportViewModel; } var m = new CustomReportsModel(DbUtil.Db, orgId); var orgName = (orgId.HasValue) ? DbUtil.Db.Organizations.SingleOrDefault(o => o.OrganizationId == orgId.Value).OrganizationName : null; CustomReportViewModel model; if (string.IsNullOrEmpty(reportName)) { model = new CustomReportViewModel(orgId, queryId, orgName, GetAllStandardColumns(m)); return View(model); } model = new CustomReportViewModel(orgId, queryId, orgName, GetAllStandardColumns(m), reportName); var reportXml = m.GetReportByName(reportName); if (reportXml == null) throw new Exception("Report not found."); var columns = MapXmlToCustomReportColumn(reportXml); var showOnOrgIdValue = reportXml.AttributeOrNull("showOnOrgId"); int showOnOrgId; if (!string.IsNullOrEmpty(showOnOrgIdValue) && int.TryParse(showOnOrgIdValue, out showOnOrgId)) model.RestrictToThisOrg = showOnOrgId == orgId; model.SetSelectedColumns(columns); if (originalReportViewModel != null) model.ReportName = originalReportViewModel.ReportName; var alreadySaved = TempData[TempDataSuccessfulSaved] as bool?; model.CustomReportSuccessfullySaved = alreadySaved.GetValueOrDefault(); return View(model); }
public ActionResult CustomReport(Guid id, string report) { var m = new CustomReportsModel(DbUtil.Db); return m.Result(id, report); }