public PartialViewResult ImportGdbFile(ProjectPrimaryKey projectPrimaryKey)
        {
            var project   = projectPrimaryKey.EntityObject;
            var viewModel = new ImportGdbFileViewModel();

            return(ViewImportGdbFile(viewModel, project.ProjectID));
        }
Beispiel #2
0
        public ActionResult ImportGdbFile(ProjectPrimaryKey projectPrimaryKey, ImportGdbFileViewModel viewModel)
        {
            var project = projectPrimaryKey.EntityObject;

            if (!ModelState.IsValid)
            {
                return(ViewImportGdbFile(viewModel, project.ProjectID));
            }

            var httpPostedFileBase = viewModel.FileResourceData;
            var fileEnding         = ".gdb.zip";

            using (var disposableTempFile = DisposableTempFile.MakeDisposableTempFileEndingIn(fileEnding))
            {
                var gdbFile = disposableTempFile.FileInfo;
                httpPostedFileBase.SaveAs(gdbFile.FullName);
                var pls = project.ProjectLocationStagings.ToList();
                foreach (var projectLocationStaging in pls)
                {
                    projectLocationStaging.DeleteFull(HttpRequestStorage.DatabaseEntities);
                }
                project.ProjectLocationStagings.Clear();
                ProjectLocationStaging.CreateProjectLocationStagingListFromGdb(gdbFile, project, CurrentPerson);
            }
            return(ApproveGisUpload(project));
        }
        public ActionResult ImportGdbFile(ProjectPrimaryKey projectPrimaryKey, ImportGdbFileViewModel viewModel)
        {
            var project = projectPrimaryKey.EntityObject;

            if (!ModelState.IsValid)
            {
                return(ViewImportGdbFile(viewModel, project.ProjectID));
            }

            var httpPostedFileBase = viewModel.FileResourceData;
            var isKml      = httpPostedFileBase.FileName.EndsWith(".kml");
            var isKmz      = httpPostedFileBase.FileName.EndsWith(".kmz");
            var fileEnding = isKml ? ".kml" : isKmz ? ".kmz" : ".gdb.zip";

            using (var disposableTempFile = DisposableTempFile.MakeDisposableTempFileEndingIn(fileEnding))
            {
                var disposableTempFileFileInfo = disposableTempFile.FileInfo;
                httpPostedFileBase.SaveAs(disposableTempFileFileInfo.FullName);
                foreach (var projectLocationStaging in project.ProjectLocationStagings.ToList())
                {
                    projectLocationStaging.DeleteFull(HttpRequestStorage.DatabaseEntities);
                }

                try
                {
                    if (isKml)
                    {
                        ProjectLocationStagingModelExtensions.CreateProjectLocationStagingListFromKml(
                            disposableTempFileFileInfo, httpPostedFileBase.FileName, project, CurrentFirmaSession);
                    }
                    else if (isKmz)
                    {
                        ProjectLocationStagingModelExtensions.CreateProjectLocationStagingListFromKmz(
                            disposableTempFileFileInfo, httpPostedFileBase.FileName, project, CurrentFirmaSession);
                    }
                    else
                    {
                        ProjectLocationStagingModelExtensions.CreateProjectLocationStagingListFromGdb(
                            disposableTempFileFileInfo, httpPostedFileBase.FileName, project, CurrentFirmaSession);
                    }
                    // Run a quick test to see if the uploaded geometries are going to be reducible later.
                    // If they aren't, we can throw the SitkaGeometryDisplayErrorException to capture a record of the uploaded file.
                    var mockGeometries = project.ProjectLocationStagings.SelectMany(x =>
                                                                                    x.ToGeoJsonFeatureCollection().Features.Select(y => y.ToSqlGeometry())).ToList();
                    Check.Assert(DbSpatialHelper.CanReduce(mockGeometries), new SitkaGeometryDisplayErrorException("Could not reduce the uploaded geometries."));
                }
                catch (SitkaGeometryDisplayErrorException exception)
                {
                    string preservedFilenameFullPath = ProjectLocationStagingModelExtensions.PreserveFailedLocationImportFile(httpPostedFileBase);
                    throw new SitkaGeometryDisplayErrorException(exception.Message, preservedFilenameFullPath);
                }
            }
            return(ApproveGisUpload(project));
        }
        private PartialViewResult ViewImportGdbFile(ImportGdbFileViewModel viewModel, int projectID)
        {
            var mapFormID       = GenerateEditProjectLocationFormID(projectID);
            var newGisUploadUrl = SitkaRoute <ProjectLocationController> .BuildUrlFromExpression(x => x.ImportGdbFile(projectID, null));

            var approveGisUploadUrl = SitkaRoute <ProjectLocationController> .BuildUrlFromExpression(x => x.ApproveGisUpload(projectID, null));

            var viewData = new ImportGdbFileViewData(mapFormID, newGisUploadUrl, approveGisUploadUrl);

            return(RazorPartialView <ImportGdbFile, ImportGdbFileViewData, ImportGdbFileViewModel>(viewData, viewModel));
        }