예제 #1
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var errors = new List <ValidationResult>();

            FileResourceModelExtensions.ValidateFileSize(FileResourceData, errors, GeneralUtility.NameOf(() => FileResourceData));
            return(errors);
        }
예제 #2
0
        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());
        }
예제 #3
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var errors      = new List <ValidationResult>();
            var maxFileSize = (1024 ^ 2) * 50 * 1000; // 50 MB

            FileResourceModelExtensions.ValidateFileSize(FileResourceData, errors, GeneralUtility.NameOf(() => FileResourceData), maxFileSize);
            return(errors);
        }
예제 #4
0
        public void UpdateModel(TenantAttribute tenantAttribute, FirmaSession currentFirmaSession, DatabaseEntities databaseEntities)
        {
            var attributeTenantStyleSheetFileResource = tenantAttribute.TenantStyleSheetFileResourceInfo;

            tenantAttribute.TenantStyleSheetFileResourceInfo = FileResourceModelExtensions.CreateNewFromHttpPostedFileAndSave(TenantStyleSheetFileResourceData, currentFirmaSession);
            attributeTenantStyleSheetFileResource?.FileResourceData.Delete(databaseEntities);
            attributeTenantStyleSheetFileResource?.Delete(databaseEntities);
        }
예제 #5
0
        public ContentResult CkEditorUploadFileResourceForCustomPage(CustomPagePrimaryKey customPagePrimaryKey, CkEditorImageUploadViewModel viewModel)
        {
            var fileResourceInfo = FileResourceModelExtensions.CreateNewFromHttpPostedFileAndSave(viewModel.upload, CurrentFirmaSession);
            var customPage       = customPagePrimaryKey.EntityObject;
            var ppImage          = new CustomPageImage(customPage, fileResourceInfo);

            HttpRequestStorage.DatabaseEntities.AllCustomPageImages.Add(ppImage);
            return(Content(viewModel.GetCkEditorJavascriptContentToReturn(fileResourceInfo)));
        }
예제 #6
0
        public ContentResult CkEditorUploadFileResourceForGeospatialAreaDescription(GeospatialAreaPrimaryKey geospatialAreaPrimaryKey, CkEditorImageUploadViewModel viewModel)
        {
            var fileResourceInfo = FileResourceModelExtensions.CreateNewFromHttpPostedFileAndSave(viewModel.upload, CurrentFirmaSession);
            var geospatialArea   = geospatialAreaPrimaryKey.EntityObject;
            var ppImage          = new GeospatialAreaImage(geospatialArea, fileResourceInfo);

            HttpRequestStorage.DatabaseEntities.AllGeospatialAreaImages.Add(ppImage);
            return(Content(viewModel.GetCkEditorJavascriptContentToReturn(fileResourceInfo)));
        }
예제 #7
0
        public ContentResult CkEditorUploadFileResourceForOrganizationDescription(OrganizationPrimaryKey organizationPrimaryKey, CkEditorImageUploadViewModel viewModel)
        {
            var fileResourceInfo = FileResourceModelExtensions.CreateNewFromHttpPostedFileAndSave(viewModel.upload, CurrentFirmaSession);
            var organization     = organizationPrimaryKey.EntityObject;
            var ppImage          = new OrganizationImage(organization, fileResourceInfo);

            HttpRequestStorage.DatabaseEntities.AllOrganizationImages.Add(ppImage);
            return(Content(viewModel.GetCkEditorJavascriptContentToReturn(fileResourceInfo)));
        }
예제 #8
0
 public override void UpdateModel(ProjectFirmaModels.Models.ProjectImage projectImage, FirmaSession currentFirmaSession)
 {
     base.UpdateModel(projectImage, currentFirmaSession);
     projectImage.FileResourceInfo = FileResourceModelExtensions.CreateNewFromHttpPostedFileAndSave(FileResourceData, currentFirmaSession);
     if (projectImage.Project.ProjectImages.All(x => x.ProjectImageID == projectImage.ProjectImageID))
     {
         projectImage.IsKeyPhoto = true;
     }
 }
예제 #9
0
        public ContentResult CkEditorUploadFileResourceForFieldDefinition(FieldDefinitionPrimaryKey fieldDefinitionPrimaryKey, CkEditorImageUploadViewModel viewModel)
        {
            var fileResourceInfo = FileResourceModelExtensions.CreateNewFromHttpPostedFileAndSave(viewModel.upload, CurrentFirmaSession);
            var fieldDefinition  = fieldDefinitionPrimaryKey.EntityObject;
            var image            = new FieldDefinitionDataImage(fieldDefinition.GetFieldDefinitionData().FieldDefinitionDataID, fileResourceInfo.FileResourceInfoID);

            HttpRequestStorage.DatabaseEntities.AllFieldDefinitionDataImages.Add(image);
            return(Content(viewModel.GetCkEditorJavascriptContentToReturn(fileResourceInfo)));
        }
예제 #10
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var errors = new List <ValidationResult>();

            FileResourceModelExtensions.ValidateFileSize(FileResourceData, errors, GeneralUtility.NameOf(() => FileResourceData));

            using (var disposableTempFile = DisposableTempFile.MakeDisposableTempFileEndingIn(".gdb.zip"))
            {
                var gdbFile = disposableTempFile.FileInfo;
                FileResourceData.SaveAs(gdbFile.FullName);

                var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(FirmaWebConfiguration.Ogr2OgrExecutable,
                                                                            LtInfoGeometryConfiguration.DefaultCoordinateSystemId,
                                                                            FirmaWebConfiguration.HttpRuntimeExecutionTimeout.TotalMilliseconds);

                List <string> featureClassNames = null;
                try
                {
                    var ogrInfoFileInfo = new FileInfo(FirmaWebConfiguration.OgrInfoExecutable);
                    featureClassNames = OgrInfoCommandLineRunner.GetFeatureClassNamesFromFileGdb(ogrInfoFileInfo, gdbFile, gdbFile.Name, Ogr2OgrCommandLineRunner.DefaultTimeOut);
                }
                catch (Exception e)
                {
                    errors.Add(new ValidationResult("There was a problem uploading your file geodatabase. Verify it meets the requirements and is not corrupt."));
                    SitkaLogger.Instance.LogDetailedErrorMessage(e);
                }

                if (featureClassNames != null)
                {
                    var featureClasses = featureClassNames.ToDictionary(x => x,
                                                                        x =>
                    {
                        try
                        {
                            var geoJson = ogr2OgrCommandLineRunner.ImportFileGdbToGeoJson(gdbFile, x, false);
                            return(JsonTools.DeserializeObject <FeatureCollection>(geoJson));
                        }
                        catch (Exception e)
                        {
                            errors.Add(new ValidationResult($"There was a problem processing the Feature Class \"{x}\"."));
                            SitkaLogger.Instance.LogDetailedErrorMessage(e);
                            return(null);
                        }
                    }).Where(x => x.Value != null && OrganizationBoundaryStaging.IsUsableFeatureCollectionGeoJson(x.Value));

                    if (!featureClasses.Any())
                    {
                        errors.Add(new ValidationResult("There are no usable Feature Classes in the uploaded file. Feature Classes must contain Polygon and/or Multi-Polygon features."));
                    }
                }
            }

            return(errors);
        }
        public void UpdateModel(ProjectUpdateBatch projectUpdateBatch, FirmaSession currentFirmaSession)
        {
            CheckForNotNullProjectUpdateBatchId();
            var fileResourceInfo = FileResourceModelExtensions.CreateNewFromHttpPostedFile(UploadedFile, currentFirmaSession.Person);

            HttpRequestStorage.DatabaseEntities.AllFileResourceInfos.Add(fileResourceInfo);
            var projectAttachment = new ProjectAttachmentUpdate(projectUpdateBatch.ProjectUpdateBatchID, fileResourceInfo.FileResourceInfoID, AttachmentTypeID, DisplayName)
            {
                Description = Description
            };

            projectUpdateBatch.ProjectAttachmentUpdates.Add(projectAttachment);
        }
        public virtual IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            CheckForNotNullProjectId();
            var validationResults = new List <ValidationResult>();

            FileResourceModelExtensions.ValidateFileSize(UploadedFile, validationResults, "File");

            // Attachments must have unique display names at the project and attachment type level
            if (HttpRequestStorage.DatabaseEntities.ProjectAttachments.Any(x => x.ProjectID == ProjectID && x.DisplayName == DisplayName && x.AttachmentTypeID == AttachmentTypeID))
            {
                AttachmentTypePrimaryKey attachmentTypePrimaryKey = AttachmentTypeID;
                var attachmentType = attachmentTypePrimaryKey.EntityObject;

                validationResults.Add(new SitkaValidationResult <NewProjectAttachmentViewModel, string>($"There is already an attachment with the display name \"{DisplayName}\" under the {attachmentType.AttachmentTypeName} attachment type for this {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()}.", m => m.DisplayName));
            }

            return(validationResults);
        }
예제 #13
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var errors         = new List <ValidationResult>();
            var reportTemplate = HttpRequestStorage.DatabaseEntities.ReportTemplates.SingleOrDefault(x => x.DisplayName == DisplayName);

            if (reportTemplate != null && reportTemplate.ReportTemplateID != ReportTemplateID)
            {
                errors.Add(new SitkaValidationResult <EditViewModel, string>("This Display Name is already being used by another Report Template", x => x.DisplayName));
            }

            if (FileResourceData == null && FileResourceInfoID == null)
            {
                errors.Add(new SitkaValidationResult <EditViewModel, HttpPostedFileBase>("You cannot have a report template without a template file.", x => x.FileResourceData));
            }

            if (FileResourceData != null)
            {
                FileResourceModelExtensions.ValidateFileSize(FileResourceData, errors, GeneralUtility.NameOf(() => FileResourceData));
            }
            return(errors);
        }
예제 #14
0
        public void UpdateModel(ProjectFirmaModels.Models.Classification classification, FirmaSession currentFirmaSession, DatabaseEntities databaseEntities)
        {
            classification.DisplayName = DisplayName;
            classification.ClassificationDescription = ClassificationDescription;
            classification.GoalStatement             = GoalStatement;

            if (DeleteCurrentKeyImage)
            {
                var oldKeyImageFileResourceInfo = classification.KeyImageFileResourceInfo;
                classification.KeyImageFileResourceInfo   = null;
                classification.KeyImageFileResourceInfoID = null;
                oldKeyImageFileResourceInfo.FileResourceData.Delete(databaseEntities);
                oldKeyImageFileResourceInfo.Delete(databaseEntities);
            }

            if (KeyImageFileResourceData != null)
            {
                classification.KeyImageFileResourceInfo = FileResourceModelExtensions.CreateNewFromHttpPostedFileAndSave(KeyImageFileResourceData, currentFirmaSession);
            }

            classification.ThemeColor = ThemeColor;
        }
예제 #15
0
        public void UpdateModel(ProjectFirmaModels.Models.Organization organization, FirmaSession currentFirmaSession, DatabaseEntities databaseEntities)
        {
            organization.OrganizationName      = OrganizationName;
            organization.OrganizationShortName = OrganizationShortName;
            organization.OrganizationTypeID    = OrganizationTypeID.Value;
            organization.IsActive = IsActive;
            organization.PrimaryContactPersonID = PrimaryContactPersonID;
            organization.OrganizationUrl        = OrganizationUrl;
            if (LogoFileResourceData != null)
            {
                var oldLogoFileResourceInfo = organization.LogoFileResourceInfo;
                organization.LogoFileResourceInfo = FileResourceModelExtensions.CreateNewFromHttpPostedFileAndSave(LogoFileResourceData, currentFirmaSession);
                oldLogoFileResourceInfo?.FileResourceData.Delete(databaseEntities);
                oldLogoFileResourceInfo?.Delete(databaseEntities);
            }

            var isSitkaAdmin = new SitkaAdminFeature().HasPermissionByFirmaSession(currentFirmaSession);

            if (isSitkaAdmin)
            {
                organization.KeystoneOrganizationGuid = KeystoneOrganizationGuid;
            }
        }
예제 #16
0
 public override void UpdateModel(ProjectFirmaModels.Models.FirmaHomePageImage firmaHomePageImage, FirmaSession currentFirmaSession)
 {
     base.UpdateModel(firmaHomePageImage, currentFirmaSession);
     firmaHomePageImage.FileResourceInfo = FileResourceModelExtensions.CreateNewFromHttpPostedFileAndSave(FileResourceData, currentFirmaSession);
 }
예제 #17
0
 public override void UpdateModel(DocumentLibraryDocument documentLibraryDocument, FirmaSession currentFirmaSession, ICollection <DocumentLibraryDocumentRole> allDocumentLibraryDocumentRoles)
 {
     documentLibraryDocument.FileResourceInfo  = FileResourceModelExtensions.CreateNewFromHttpPostedFileAndSave(FileResourceData, currentFirmaSession);
     documentLibraryDocument.DocumentLibraryID = DocumentLibraryID;
     base.UpdateModel(documentLibraryDocument, currentFirmaSession, allDocumentLibraryDocumentRoles);
 }