Esempio n. 1
0
        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));
            }
        }
        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));
        }
 public void UpdateModel(GeospatialAreaType geospatialAreaType)
 {
     geospatialAreaType.DisplayOnAllProjectMaps = DisplayOnAllMaps;
     geospatialAreaType.OnByDefaultOnProjectMap = LayerIsOnByDefaultOnProjectMap;
     geospatialAreaType.OnByDefaultOnOtherMaps  = LayerIsOnByDefaultOnOtherMaps;
     geospatialAreaType.ServiceUrl = ServiceUrl;
 }
 public GeospatialAreaTypeSimple(GeospatialAreaType geospatialAreaType)
 {
     GeospatialAreaTypeID             = geospatialAreaType.GeospatialAreaTypeID;
     GeospatialAreaTypeName           = geospatialAreaType.GeospatialAreaTypeName;
     GeospatialAreaTypeNamePluralized = geospatialAreaType.GeospatialAreaTypeNamePluralized;
     GeospatialAreaTypeLayerName      = geospatialAreaType.GeospatialAreaLayerName;
     GeospatialAreaTypeMapServiceUrl  = geospatialAreaType.MapServiceUrl();
 }
 public EditGeospatialAreaMapLayerViewModel(GeospatialAreaType geospatialAreaType)
 {
     GeospatialAreaTypeID           = geospatialAreaType.GeospatialAreaTypeID;
     DisplayOnAllMaps               = geospatialAreaType.DisplayOnAllProjectMaps;
     LayerIsOnByDefaultOnProjectMap = geospatialAreaType.OnByDefaultOnProjectMap;
     LayerIsOnByDefaultOnOtherMaps  = geospatialAreaType.OnByDefaultOnOtherMaps;
     ServiceUrl = geospatialAreaType.ServiceUrl;
 }
Esempio n. 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));
 }
Esempio n. 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));
        }
Esempio n. 8
0
 public GeospatialAreaViewData(FirmaSession currentFirmaSession,
     ProjectFirmaModels.Models.Project project,
     GeospatialAreaType geospatialAreaType,
     ProposalSectionsStatus proposalSectionsStatus,
     EditProjectGeospatialAreasViewData editProjectGeospatialAreasViewData)
     : base(currentFirmaSession, project, geospatialAreaType.GeospatialAreaTypeNamePluralized, proposalSectionsStatus)
 {
     EditProjectGeospatialAreasViewData = editProjectGeospatialAreasViewData;
 }
        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.");
            }
        }
 // 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));
 }
Esempio n. 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));
 }
Esempio n. 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;
        }
Esempio n. 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);
        }
Esempio n. 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()));
        }
Esempio n. 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;
        }
 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;
 }
Esempio n. 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);
        }
        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);
        }
Esempio n. 19
0
            public static GeospatialAreaType Create()
            {
                var geospatialAreaType = GeospatialAreaType.CreateNewBlank();

                return(geospatialAreaType);
            }
Esempio n. 20
0
 public static string GetEditGeospatialAreasUrl(this GeospatialAreaType geospatialAreaType, Project project)
 {
     return(SitkaRoute <ProjectGeospatialAreaController> .BuildUrlFromExpression(x =>
                                                                                 x.EditProjectGeospatialAreas(project.ProjectID, geospatialAreaType.GeospatialAreaTypeID)));
 }
Esempio n. 21
0
 public static bool IsProjectGeospatialAreaValid(this ProjectUpdateBatch projectUpdateBatch, GeospatialAreaType geospatialAreaType)
 {
     return(projectUpdateBatch.ValidateProjectGeospatialArea(geospatialAreaType).IsValid);
 }
Esempio n. 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;
        }
Esempio n. 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);
 }
Esempio n. 24
0
 public static string GetSyncUrl(this GeospatialAreaType geospatialAreaType)
 {
     return(SyncUrlTemplate.ParameterReplace(geospatialAreaType.GeospatialAreaTypeID));
 }
Esempio n. 25
0
        public static string MapServiceUrl(this GeospatialAreaType geospatialAreaType)
        {
            var geoServerNamespace = MultiTenantHelpers.GetTenantAttributeFromCache().GeoServerNamespace;

            return($"{FirmaWebConfiguration.GeoServerUrl}{geoServerNamespace}/wms");
        }
Esempio n. 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());
        }
Esempio n. 27
0
 public static string GetEditMapLayerUrl(this GeospatialAreaType geospatialAreaType)
 {
     return(EditMapLayerUrlTemplate.ParameterReplace(geospatialAreaType.GeospatialAreaTypeID));
 }
Esempio n. 28
0
 public static void RenderPartialView(HtmlHelper <object> html, GeospatialAreaType geospatialAreaType, FirmaSession firmaSession)
 {
     html.RenderRazorSitkaPartial <ViewPageContent, ViewPageContentViewData>(new ViewPageContentViewData(geospatialAreaType, firmaSession));
 }
Esempio n. 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);
        }
Esempio n. 30
0
 public EditGeospatialAreaMapLayerViewData(GeospatialAreaType geospatialAreaType)
 {
     GeospatialAreaType = geospatialAreaType;
     AreGeospatialAreasExternallySourced = MultiTenantHelpers.AreGeospatialAreasExternallySourced();
 }