示例#1
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);
        }
示例#2
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;
        }