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(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 })); }