コード例 #1
0
ファイル: RestApiClient.cs プロジェクト: sitkatech/alevin
        public static SyncResult SyncGeospatialAreaTypeFromService(GeospatialAreaType geospatialAreaType)
        {
            SitkaHttpApplication.Logger.Info($"Syncing data for Geospatial Area Type {geospatialAreaType.GeospatialAreaTypeName} from {geospatialAreaType.ServiceUrl}");
            string statusMessage;

            try
            {
                var responseData          = MakeApiRequest("Geospatial Area Type", geospatialAreaType.ServiceUrl);
                var lastSucessfulResponse = HttpRequestStorage.DatabaseEntities.GeospatialAreaRawDatas.SingleOrDefault(x => x.GeospatialAreaTypeID == geospatialAreaType.GeospatialAreaTypeID);

                var optionalSkippedDeletionWarning = GeospatialAreaTypeModelExtensions.ProcessApiResponse(geospatialAreaType, responseData, HttpRequestStorage.DatabaseEntities, SitkaWebConfiguration.DatabaseConnectionString);
                // Record this response as the latest response for next time
                if (lastSucessfulResponse == null)
                {
                    lastSucessfulResponse = new GeospatialAreaRawData(geospatialAreaType.GeospatialAreaTypeID);
                    HttpRequestStorage.DatabaseEntities.AllGeospatialAreaRawDatas.Add(lastSucessfulResponse);
                }
                lastSucessfulResponse.ResultJson = responseData;

                if (optionalSkippedDeletionWarning != null)
                {
                    return(new SyncResult(optionalSkippedDeletionWarning, false, true));
                }
                statusMessage = $"Geospatial area sync for {geospatialAreaType.GeospatialAreaTypeName} successful";
                return(new SyncResult(statusMessage, false, false));
            }
            catch (Exception e)
            {
                statusMessage = $"Geospatial area sync for {geospatialAreaType.GeospatialAreaTypeName} failed";
                SitkaLogger.Instance.LogDetailedErrorMessage(statusMessage + " with an exception", e);
                return(new SyncResult(statusMessage, true, false));
            }
        }
コード例 #2
0
        private PartialViewResult ViewEditProjectGeospatialAreas(EditProjectGeospatialAreasViewModel viewModel,
                                                                 Project project, GeospatialAreaType geospatialAreaType)
        {
            var userCanViewPrivateLocations = CurrentFirmaSession.UserCanViewPrivateLocations(project);
            var boundingBox = ProjectLocationSummaryMapInitJson.GetProjectBoundingBox(project, userCanViewPrivateLocations);
            var layers      = MapInitJson.GetGeospatialAreaMapLayersForGeospatialAreaType(geospatialAreaType);

            layers.AddRange(MapInitJson.GetProjectLocationSimpleAndDetailedMapLayers(project, CurrentFirmaSession));
            var mapInitJson = new MapInitJson("projectGeospatialAreaMap", 0, layers, MapInitJson.GetExternalMapLayers(), boundingBox)
            {
                AllowFullScreen = false, DisablePopups = true
            };
            var geospatialAreaIDs                 = viewModel.GeospatialAreaIDs ?? new List <int>();
            var geospatialAreasInViewModel        = HttpRequestStorage.DatabaseEntities.GeospatialAreas.Where(x => geospatialAreaIDs.Contains(x.GeospatialAreaID)).ToList();
            var editProjectGeospatialAreasPostUrl = SitkaRoute <ProjectGeospatialAreaController> .BuildUrlFromExpression(c => c.EditProjectGeospatialAreas(project, geospatialAreaType, null));

            var editProjectGeospatialAreasFormID = GetEditProjectGeospatialAreasFormID();

            var geospatialAreasContainingProjectSimpleLocation = GeospatialAreaModelExtensions.GetGeospatialAreasContainingProjectLocation(project, geospatialAreaType.GeospatialAreaTypeID).ToList();

            var viewData = new EditProjectGeospatialAreasViewData(CurrentFirmaSession, mapInitJson,
                                                                  geospatialAreasInViewModel, editProjectGeospatialAreasPostUrl, editProjectGeospatialAreasFormID,
                                                                  project.HasProjectLocationPoint(userCanViewPrivateLocations), project.HasProjectLocationDetailed(userCanViewPrivateLocations), geospatialAreaType,
                                                                  geospatialAreasContainingProjectSimpleLocation, null);

            return(RazorPartialView <EditProjectGeospatialAreas, EditProjectGeospatialAreasViewData, EditProjectGeospatialAreasViewModel>(viewData, viewModel));
        }
コード例 #3
0
 public void UpdateModel(GeospatialAreaType geospatialAreaType)
 {
     geospatialAreaType.DisplayOnAllProjectMaps = DisplayOnAllMaps;
     geospatialAreaType.OnByDefaultOnProjectMap = LayerIsOnByDefaultOnProjectMap;
     geospatialAreaType.OnByDefaultOnOtherMaps  = LayerIsOnByDefaultOnOtherMaps;
     geospatialAreaType.ServiceUrl = ServiceUrl;
 }
コード例 #4
0
 public GeospatialAreaTypeSimple(GeospatialAreaType geospatialAreaType)
 {
     GeospatialAreaTypeID             = geospatialAreaType.GeospatialAreaTypeID;
     GeospatialAreaTypeName           = geospatialAreaType.GeospatialAreaTypeName;
     GeospatialAreaTypeNamePluralized = geospatialAreaType.GeospatialAreaTypeNamePluralized;
     GeospatialAreaTypeLayerName      = geospatialAreaType.GeospatialAreaLayerName;
     GeospatialAreaTypeMapServiceUrl  = geospatialAreaType.MapServiceUrl();
 }
コード例 #5
0
 public EditGeospatialAreaMapLayerViewModel(GeospatialAreaType geospatialAreaType)
 {
     GeospatialAreaTypeID           = geospatialAreaType.GeospatialAreaTypeID;
     DisplayOnAllMaps               = geospatialAreaType.DisplayOnAllProjectMaps;
     LayerIsOnByDefaultOnProjectMap = geospatialAreaType.OnByDefaultOnProjectMap;
     LayerIsOnByDefaultOnOtherMaps  = geospatialAreaType.OnByDefaultOnOtherMaps;
     ServiceUrl = geospatialAreaType.ServiceUrl;
 }
コード例 #6
0
 public ViewPageContentViewData(GeospatialAreaType geospatialAreaType, FirmaSession currentFirmaSession)
 {
     FirmaPageContentHtmlString = geospatialAreaType.GetFirmaPageContentHtmlString();
     FirmaPageDisplayName       = geospatialAreaType.GetFirmaPageDisplayName();
     ShowEditButton             = new GeospatialAreaManageFeature().HasPermissionByFirmaSession(currentFirmaSession);
     HasPageContent             = geospatialAreaType.HasPageContent();
     EditPageContentUrl         = SitkaRoute <GeospatialAreaController> .BuildUrlFromExpression(t => t.EditInDialog(geospatialAreaType));
 }
コード例 #7
0
        private PartialViewResult ViewSyncGeospatialAreaType(GeospatialAreaType geospatialAreaType, ConfirmDialogFormViewModel viewModel)
        {
            var confirmMessage =
                $"Are you sure you want to update the features for map layer: {geospatialAreaType.GeospatialAreaTypeName}? This will update the list of map layers based on the map service.";
            var viewData = new ConfirmDialogFormViewData(confirmMessage);

            return(RazorPartialView <ConfirmDialogForm, ConfirmDialogFormViewData, ConfirmDialogFormViewModel>(viewData, viewModel));
        }
コード例 #8
0
 public GeospatialAreaViewData(FirmaSession currentFirmaSession,
     ProjectFirmaModels.Models.Project project,
     GeospatialAreaType geospatialAreaType,
     ProposalSectionsStatus proposalSectionsStatus,
     EditProjectGeospatialAreasViewData editProjectGeospatialAreasViewData)
     : base(currentFirmaSession, project, geospatialAreaType.GeospatialAreaTypeNamePluralized, proposalSectionsStatus)
 {
     EditProjectGeospatialAreasViewData = editProjectGeospatialAreasViewData;
 }
コード例 #9
0
        public GeospatialAreaValidationResult(bool isIncomplete, GeospatialAreaType geospatialAreaType)
        {
            _warningMessages = new List <string>();

            if (isIncomplete)
            {
                var geospatialAreaTypeName = geospatialAreaType.GeospatialAreaTypeName;
                _warningMessages.Add($"Select at least one {geospatialAreaTypeName}, or if {geospatialAreaTypeName} information is unavailable/irrelevant provide explanatory information in the Notes section.");
            }
        }
コード例 #10
0
 // This is called for editor maps where layer initial visibility may be different from what's configured on the GeospatialAreaType
 public static LayerGeoJson GetGeospatialAreaWmsLayerGeoJson(this GeospatialAreaType geospatialAreaType,
                                                             string layerColor, decimal layerOpacity,
                                                             LayerInitialVisibility.LayerInitialVisibilityEnum layerInitialVisibility)
 {
     return(new LayerGeoJson(geospatialAreaType.GeospatialAreaTypeNamePluralized,
                             geospatialAreaType.MapServiceUrl(),
                             geospatialAreaType.GeospatialAreaLayerName, MapTooltipUrlTemplate.UrlTemplateString, layerColor,
                             layerOpacity,
                             layerInitialVisibility));
 }
コード例 #11
0
 public IndexViewData(FirmaSession currentFirmaSession, GeospatialAreaType geospatialAreaType, MapInitJson mapInitJson) : base(currentFirmaSession)
 {
     PageTitle          = $"{geospatialAreaType.GeospatialAreaTypeNamePluralized}";
     MapInitJson        = mapInitJson;
     GeospatialAreaType = geospatialAreaType;
     GridSpec           = new IndexGridSpec(currentFirmaSession, geospatialAreaType)
     {
         ObjectNameSingular = $"{geospatialAreaType.GeospatialAreaTypeName}", ObjectNamePlural = $"{geospatialAreaType.GeospatialAreaTypeNamePluralized}", SaveFiltersInCookie = true
     };
     GridName    = "geospatialAreasGrid";
     GridDataUrl = SitkaRoute <GeospatialAreaController> .BuildUrlFromExpression(tc => tc.IndexGridJsonData(geospatialAreaType));
 }
コード例 #12
0
        public GeospatialAreaViewData(FirmaSession currentFirmaSession,
                                      ProjectFirmaModels.Models.ProjectUpdate projectUpdate,
                                      EditProjectGeospatialAreasViewData editProjectGeospatialAreasViewData,
                                      ProjectLocationSummaryViewData projectLocationSummaryViewData,
                                      GeospatialAreaValidationResult geospatialAreaValidationResult,
                                      ProjectUpdateStatus projectUpdateStatus, GeospatialAreaType geospatialAreaType) : base(currentFirmaSession, projectUpdate.ProjectUpdateBatch, projectUpdateStatus, geospatialAreaValidationResult.GetWarningMessages(), geospatialAreaType.GeospatialAreaTypeNamePluralized)
        {
            EditProjectGeospatialAreasViewData = editProjectGeospatialAreasViewData;
            ProjectLocationSummaryViewData     = projectLocationSummaryViewData;
            RefreshUrl = SitkaRoute <ProjectUpdateController> .BuildUrlFromExpression(x => x.RefreshProjectGeospatialArea(projectUpdate.ProjectUpdateBatch.Project, geospatialAreaType));

            SectionCommentsViewData = new SectionCommentsViewData(projectUpdate.ProjectUpdateBatch.LocationSimpleComment, projectUpdate.ProjectUpdateBatch.IsReturned());
            GeospatialAreaType      = geospatialAreaType;
        }
コード例 #13
0
        public static string GetPopulationStringForProjectInBiOpAnnualReportGrid(this GeospatialAreaType geospatialAreaType, Project project, bool returnRawHtmlUrlString)
        {
            var returnString = "";

            if (geospatialAreaType?.PopulationGeospatialAreaType != null)
            {
                var populationGeospatialAreaType     = geospatialAreaType.PopulationGeospatialAreaType;
                var projectGeospatialAreas           = project.ProjectGeospatialAreas.Select(x => x.GeospatialArea).ToList();
                var projectGeospatialAreasWithinType = projectGeospatialAreas.Where(x => x.GeospatialAreaTypeID == populationGeospatialAreaType.GeospatialAreaTypeID).ToList();

                returnString = String.Join(", ", projectGeospatialAreasWithinType.Select(x => returnRawHtmlUrlString ? x.GetDisplayNameAsUrl().ToString() : x.GetDisplayName()));
            }

            return(returnString);
        }
コード例 #14
0
        public static HtmlString GetGeoJsonLinkHtmlString(this GeospatialAreaType geospatialAreaType)
        {
            var mapServiceUri = new UriBuilder(geospatialAreaType.MapServiceUrl());

            mapServiceUri.Path = mapServiceUri.Path.Replace("/wms", "/ows");

            NameValueCollection queryString = HttpUtility.ParseQueryString(string.Empty);

            queryString["service"]      = "WFS";
            queryString["version"]      = "1.0.0";
            queryString["request"]      = "GetFeature";
            queryString["typeName"]     = geospatialAreaType.GeospatialAreaLayerName;
            queryString["outputFormat"] = "application/json";
            queryString["maxFeatures"]  = "500";
            queryString["sortBy"]       = "PrimaryKey";
            queryString["startIndex"]   = "0";
            mapServiceUri.Query         = queryString.ToString();

            return(UrlTemplate.MakeHrefString(mapServiceUri.ToString(), mapServiceUri.ToString()));
        }
コード例 #15
0
        public EditProjectGeospatialAreasViewData(FirmaSession currentFirmaSession, MapInitJson mapInitJson,
                                                  List <ProjectFirmaModels.Models.GeospatialArea> geospatialAreasInViewModel, string editProjectGeospatialAreasUrl,
                                                  string editProjectGeospatialAreasFormID, bool hasProjectLocationPoint, bool hasProjectLocationDetail,
                                                  GeospatialAreaType geospatialAreaType, List <fGeoServerGeospatialAreaAreasContainingProjectLocation_Result> geospatialAreasContainingProjectSimpleLocation, string editSimpleLocationUrl) : base(currentFirmaSession)
        {
            GeospatialAreaType = geospatialAreaType;
            GeospatialAreaIDsContainingProjectSimpleLocation = geospatialAreasContainingProjectSimpleLocation;

            ViewDataForAngular =
                new EditProjectGeospatialAreasViewDataForAngular(mapInitJson, geospatialAreasInViewModel,
                                                                 geospatialAreaType, geospatialAreasContainingProjectSimpleLocation, hasProjectLocationPoint);
            EditProjectGeospatialAreasFormID = editProjectGeospatialAreasFormID;
            EditProjectGeospatialAreasUrl    = editProjectGeospatialAreasUrl;
            HasProjectLocationPoint          = hasProjectLocationPoint;
            HasProjectLocationDetail         = hasProjectLocationDetail;

            SimplePointMarkerImg = "https://api.tiles.mapbox.com/v3/marker/pin-s-marker+838383.png";

            EditSimpleLocationUrl = editSimpleLocationUrl;
        }
コード例 #16
0
 public ProjectCustomGridConfigurationSimple(int projectCustomGridTypeID, ProjectCustomGridColumn projectCustomGridColumn, ProjectCustomAttributeType projectCustomAttributeType, GeospatialAreaType geospatialAreaType, bool isEnabled, int?sortOrder)
 {
     ProjectCustomGridTypeID        = projectCustomGridTypeID;
     ProjectCustomGridColumnID      = projectCustomGridColumn.ProjectCustomGridColumnID;
     ProjectCustomGridColumnName    = projectCustomGridColumn.ProjectCustomGridColumnDisplayName;
     ProjectCustomAttributeTypeID   = projectCustomAttributeType?.ProjectCustomAttributeTypeID;
     ProjectCustomAttributeTypeName = projectCustomAttributeType?.ProjectCustomAttributeTypeName;
     GeospatialAreaTypeID           = geospatialAreaType?.GeospatialAreaTypeID;
     GeospatialAreaTypeName         = geospatialAreaType?.GeospatialAreaTypeName;
     IsEnabled  = !projectCustomGridColumn.IsOptional || isEnabled;
     IsOptional = projectCustomGridColumn.IsOptional;
     SortOrder  = sortOrder;
 }
コード例 #17
0
        public static GeospatialAreaValidationResult ValidateProjectGeospatialArea(this ProjectUpdateBatch projectUpdateBatch, GeospatialAreaType geospatialAreaType)
        {
            var projectGeospatialAreaTypeNoteUpdate = projectUpdateBatch.ProjectGeospatialAreaTypeNoteUpdates.SingleOrDefault(x => x.GeospatialAreaTypeID == geospatialAreaType.GeospatialAreaTypeID);
            var incomplete = projectUpdateBatch.ProjectGeospatialAreaUpdates.All(x => x.GeospatialArea.GeospatialAreaTypeID != geospatialAreaType.GeospatialAreaTypeID) && projectGeospatialAreaTypeNoteUpdate == null;
            var geospatialAreaValidationResult = new GeospatialAreaValidationResult(incomplete, geospatialAreaType);

            return(geospatialAreaValidationResult);
        }
コード例 #18
0
        public static List <GeospatialAreaIndexGridSimple> GetGeospatialAreaIndexGridSimples(GeospatialAreaType geospatialAreaType, List <int> projectIDsViewableByUser)
        {
            var results = from geospatialArea in HttpRequestStorage.DatabaseEntities.GeospatialAreas
                          join projectGeospatialArea in HttpRequestStorage.DatabaseEntities.ProjectGeospatialAreas.Where(x => projectIDsViewableByUser.Contains(x.ProjectID))
                          on geospatialArea.GeospatialAreaID equals projectGeospatialArea.GeospatialAreaID
                          into x
                          where geospatialArea.GeospatialAreaTypeID == geospatialAreaType.GeospatialAreaTypeID
                          from x2 in x.DefaultIfEmpty()
                          group x2 by new { geospatialArea.GeospatialAreaID, geospatialArea.GeospatialAreaShortName } into grouped
                select new GeospatialAreaIndexGridSimple()
            {
                GeospatialAreaID           = grouped.Key.GeospatialAreaID,
                GeospatialAreaShortName    = grouped.Key.GeospatialAreaShortName,
                ProjectViewableByUserCount = grouped.Count(t => t.ProjectGeospatialAreaID > 0)
            };

            var geospatialAreaIndexGridSimplesNew = results.ToList();

            return(geospatialAreaIndexGridSimplesNew);
        }
コード例 #19
0
            public static GeospatialAreaType Create()
            {
                var geospatialAreaType = GeospatialAreaType.CreateNewBlank();

                return(geospatialAreaType);
            }
コード例 #20
0
 public static string GetEditGeospatialAreasUrl(this GeospatialAreaType geospatialAreaType, Project project)
 {
     return(SitkaRoute <ProjectGeospatialAreaController> .BuildUrlFromExpression(x =>
                                                                                 x.EditProjectGeospatialAreas(project.ProjectID, geospatialAreaType.GeospatialAreaTypeID)));
 }
コード例 #21
0
 public static bool IsProjectGeospatialAreaValid(this ProjectUpdateBatch projectUpdateBatch, GeospatialAreaType geospatialAreaType)
 {
     return(projectUpdateBatch.ValidateProjectGeospatialArea(geospatialAreaType).IsValid);
 }
コード例 #22
0
        public EditProjectGeospatialAreasViewDataForAngular(MapInitJson mapInitJson,
                                                            List <ProjectFirmaModels.Models.GeospatialArea> geospatialAreasInViewModel, GeospatialAreaType geospatialAreaType,
                                                            List <ProjectFirmaModels.Models.fGeoServerGeospatialAreaAreasContainingProjectLocation_Result> geospatialAreasContainingProjectSimpleLocation, bool hasProjectLocationPoint)
        {
            MapInitJson = mapInitJson;
            FindGeospatialAreaByNameUrl =
                SitkaRoute <ProjectGeospatialAreaController> .BuildUrlFromExpression(c =>
                                                                                     c.FindGeospatialAreaByName(geospatialAreaType, null));

            TypeAheadInputId = "geospatialAreaSearch";

            GeospatialAreaMapServiceLayerName = geospatialAreaType.GeospatialAreaLayerName;
            MapServiceUrl                    = geospatialAreaType.MapServiceUrl();
            GeospatialAreaTypeName           = geospatialAreaType.GeospatialAreaTypeName;
            GeospatialAreaTypeNamePluralized = geospatialAreaType.GeospatialAreaTypeNamePluralized;

            GeospatialAreaNameByID =
                geospatialAreasInViewModel.ToDictionary(x => x.GeospatialAreaID, x => x.GeospatialAreaShortName);

            GeospatialAreaNameByID.AddAll(
                geospatialAreasContainingProjectSimpleLocation
                .Where(x => !GeospatialAreaNameByID.ContainsKey(x.GeospatialAreaID)).ToDictionary(
                    x => x.GeospatialAreaID,
                    x => x.GeospatialAreaShortName));

            GeospatialAreaIDsContainingProjectSimpleLocation = geospatialAreasContainingProjectSimpleLocation
                                                               .Select(x => x.GeospatialAreaID).ToList();

            HasProjectLocationPoint = hasProjectLocationPoint;
        }
コード例 #23
0
 public IndexGridSpec(FirmaSession currentFirmaSession, GeospatialAreaType geospatialAreaType)
 {
     Add(geospatialAreaType.GeospatialAreaTypeName, a => UrlTemplate.MakeHrefString(GeospatialAreaModelExtensions.GetDetailUrl(a.GeospatialAreaID), a.GetGeospatialAreaShortNameWithColor()), 300, DhtmlxGridColumnFilterType.Html);
     Add($"# of {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabelPluralized()}", a => a.ProjectViewableByUserCount, 65);
 }
コード例 #24
0
 public static string GetSyncUrl(this GeospatialAreaType geospatialAreaType)
 {
     return(SyncUrlTemplate.ParameterReplace(geospatialAreaType.GeospatialAreaTypeID));
 }
コード例 #25
0
        public static string MapServiceUrl(this GeospatialAreaType geospatialAreaType)
        {
            var geoServerNamespace = MultiTenantHelpers.GetTenantAttributeFromCache().GeoServerNamespace;

            return($"{FirmaWebConfiguration.GeoServerUrl}{geoServerNamespace}/wms");
        }
コード例 #26
0
        private static bool IsGeospatialAreaUpdated(ProjectUpdateBatch projectUpdateBatch, GeospatialAreaType geospatialAreaType)
        {
            var project = projectUpdateBatch.Project;
            var originalGeospatialAreaIDs = project.ProjectGeospatialAreas.Where(x => x.GeospatialArea.GeospatialAreaTypeID == geospatialAreaType.GeospatialAreaTypeID).Select(x => x.GeospatialAreaID).ToList();
            var updatedGeospatialAreaIDs  = projectUpdateBatch.ProjectGeospatialAreaUpdates.Where(x => x.GeospatialArea.GeospatialAreaTypeID == geospatialAreaType.GeospatialAreaTypeID).Select(x => x.GeospatialAreaID).ToList();

            if (!originalGeospatialAreaIDs.Any() && !updatedGeospatialAreaIDs.Any())
            {
                return(false);
            }

            if (originalGeospatialAreaIDs.Count != updatedGeospatialAreaIDs.Count)
            {
                return(true);
            }

            var enumerable = originalGeospatialAreaIDs.Except(updatedGeospatialAreaIDs);

            return(enumerable.Any());
        }
コード例 #27
0
 public static string GetEditMapLayerUrl(this GeospatialAreaType geospatialAreaType)
 {
     return(EditMapLayerUrlTemplate.ParameterReplace(geospatialAreaType.GeospatialAreaTypeID));
 }
コード例 #28
0
 public static void RenderPartialView(HtmlHelper <object> html, GeospatialAreaType geospatialAreaType, FirmaSession firmaSession)
 {
     html.RenderRazorSitkaPartial <ViewPageContent, ViewPageContentViewData>(new ViewPageContentViewData(geospatialAreaType, firmaSession));
 }
コード例 #29
0
        public static string ProcessApiResponse(GeospatialAreaType geospatialAreaType,
                                                string responseData, DatabaseEntities dbContext, string databaseConnectionString)
        {
            var geospatialAreaTypeID   = geospatialAreaType.GeospatialAreaTypeID;
            var geospatialAreaStagings = ConvertToGeospatialStagings(responseData, dbContext, databaseConnectionString);
            var stagedExternalIDs      = geospatialAreaStagings.Select(x => x.ExternalID).ToList();
            var currentExternalIDs     = dbContext.GeospatialAreas.Where(x => x.GeospatialAreaTypeID == geospatialAreaTypeID).Select(x => x.ExternalID).ToList();
            var newGeospatialAreas     = geospatialAreaStagings.Where(x => !currentExternalIDs.Contains(x.ExternalID))
                                         .Select(x => new GeospatialArea(x.Name, geospatialAreaTypeID, x.Name)
            {
                ExternalID = x.ExternalID, GeospatialAreaFeature = x.Geometry
            }).ToList();

            dbContext.AllGeospatialAreas.AddRange(newGeospatialAreas);
            // Find entities with matching names in DB and Service
            var geospatialAreasToUpdate = dbContext.GeospatialAreas.Where(x => x.GeospatialAreaTypeID == geospatialAreaTypeID && stagedExternalIDs.Contains(x.ExternalID));

            if (geospatialAreasToUpdate.Any())
            {
                foreach (var geospatialArea in geospatialAreasToUpdate)
                {
                    // Get the corresponding feature from staging
                    var geospatialAreaStaging = geospatialAreaStagings.Single(x => x.ExternalID == geospatialArea.ExternalID);
                    // Update certain properties
                    geospatialArea.GeospatialAreaName      = geospatialAreaStaging.Name;
                    geospatialArea.GeospatialAreaShortName = geospatialAreaStaging.Name;
                    geospatialArea.GeospatialAreaFeature   = geospatialAreaStaging.Geometry;
                }
            }

            var geospatialAreasToPotentiallyDelete =
                dbContext.GeospatialAreas.Where(x => x.GeospatialAreaTypeID == geospatialAreaTypeID && !stagedExternalIDs.Contains(x.ExternalID)).ToList();

            if (geospatialAreasToPotentiallyDelete.Any())
            {
                var skippedDeletions = new List <string>();

                foreach (var geospatialArea in geospatialAreasToPotentiallyDelete)
                {
                    if (!geospatialArea.HasDependentObjects())
                    {
                        geospatialArea.Delete(dbContext);
                    }
                    else
                    {
                        skippedDeletions.Add($"<li>{geospatialArea.GeospatialAreaName}</li>");
                    }
                }

                if (skippedDeletions.Any())
                {
                    var geospatialAreaTypeName = HttpRequestStorage.DatabaseEntities.GeospatialAreaTypes
                                                 .Single(x => x.GeospatialAreaTypeID == geospatialAreaTypeID).GeospatialAreaTypeNamePluralized;
                    var skippedDeletionWarning = $"The following {geospatialAreaTypeName} were not found in the service but could not be deleted because they are still associated with other entities: " +
                                                 "<ul>" +
                                                 string.Join("", skippedDeletions.OrderBy(x => x)) +
                                                 "</ul>" +
                                                 "To delete them, remove their associations and re-run the sync.";
                    return(skippedDeletionWarning);
                }
            }

            return(null);
        }
コード例 #30
0
 public EditGeospatialAreaMapLayerViewData(GeospatialAreaType geospatialAreaType)
 {
     GeospatialAreaType = geospatialAreaType;
     AreGeospatialAreasExternallySourced = MultiTenantHelpers.AreGeospatialAreasExternallySourced();
 }