Exemple #1
0
        public ActionResult Support(SupportFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(ViewSupportImpl(viewModel, string.Empty));
            }
            var supportRequestLog = SupportRequestLogModelExtensions.Create(CurrentFirmaSession);

            viewModel.UpdateModel(supportRequestLog, CurrentFirmaSession);
            HttpRequestStorage.DatabaseEntities.AllSupportRequestLogs.Add(supportRequestLog);
            SupportRequestLogModelExtensions.SendMessage(supportRequestLog, Request.UserHostAddress, Request.UserAgent, viewModel.CurrentPageUrl, supportRequestLog.SupportRequestType, HttpRequestStorage.DatabaseEntities, FirmaWebConfiguration.DefaultSupportPersonID);
            SetMessageForDisplay("Support request sent.");
            if (CurrentFirmaSession.IsAnonymousUser())
            {
                // This is a rare place in the system where an anonymous user writes to the DB.
                // If this becomes more commonplace we can work out a more general solution.
                HttpRequestStorage.DatabaseEntities.SaveChangesWithNoAuditing(CurrentFirmaSession.TenantID);
            }
            else
            {
                // Logged in user, normal audit trail on save
                SitkaDbContext.SaveChanges();
            }

            return(new ModalDialogFormJsonResult());
        }
        public ActionResult New(EditViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(ViewEdit(viewModel));
            }

            var fileResourceInfo        = FileResourceModelExtensions.CreateNewFromHttpPostedFileAndSave(viewModel.FileResourceData, CurrentFirmaSession);
            var reportTemplateModelType = ReportTemplateModelType.All.FirstOrDefault(x => x.ReportTemplateModelTypeID == viewModel.ReportTemplateModelTypeID);
            var reportTemplateModel     = ReportTemplateModel.All.FirstOrDefault(x => x.ReportTemplateModelID == viewModel.ReportTemplateModelID);
            var reportTemplate          = ReportTemplate.CreateNewBlank(fileResourceInfo, reportTemplateModelType, reportTemplateModel);

            ReportTemplateGenerator.ValidateReportTemplate(reportTemplate, out var reportIsValid, out var errorMessage, out var sourceCode);

            if (reportIsValid)
            {
                viewModel.UpdateModel(reportTemplate, fileResourceInfo, CurrentFirmaSession, HttpRequestStorage.DatabaseEntities);
                SitkaDbContext.SaveChanges();
                SetMessageForDisplay($"Report Template \"{reportTemplate.DisplayName}\" successfully created.");
            }
            else
            {
                SetErrorForDisplay($"There was an error with this template: {errorMessage}");
                if (!sourceCode.IsEmpty())
                {
                    SetErrorWithScrollablePreForDisplay($"{sourceCode}");
                }
            }

            return(new ModalDialogFormJsonResult());
        }