Ejemplo n.º 1
0
 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));
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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 });
        }
Ejemplo n.º 4
0
        public CustomReportViewModel EditCustomReport(CustomReportViewModel originalReportViewModel, bool? alreadySaved)
        {
            var orgName = orgid.HasValue
                ? DbUtil.Db.Organizations.SingleOrDefault(o => o.OrganizationId == orgid.Value)?.OrganizationName
                : null;

            if (!Report.HasValue())
                return new CustomReportViewModel(orgid, queryid, orgName, GetAllStandardColumns());

            var vm = new CustomReportViewModel(orgid, queryid, orgName, GetAllStandardColumns(), Report);

            var reportXml = GetReportByName();
            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))
                vm.RestrictToThisOrg = showOnOrgId == orgid;

            vm.SetSelectedColumns(columns);
            vm.Columns = vm.Columns.OrderBy(cc => cc.Order).ToList();

            if (originalReportViewModel != null)
                vm.ReportName = originalReportViewModel.ReportName;
            vm.CustomReportSuccessfullySaved = alreadySaved.GetValueOrDefault();
            return vm;
        }