public PartialViewResult AddGeospatialAreaToPerformanceMeasure(PerformanceMeasurePrimaryKey performanceMeasurePrimaryKey)
        {
            var performanceMeasure = performanceMeasurePrimaryKey.EntityObject;

            var viewModel = new AddGeospatialAreaToPerformanceMeasureViewModel(performanceMeasure);

            return(ViewAddGeospatialAreaToPerformanceMeasure(performanceMeasure, viewModel));
        }
        private PartialViewResult ViewAddGeospatialAreaToPerformanceMeasure(PerformanceMeasure performanceMeasure, AddGeospatialAreaToPerformanceMeasureViewModel viewModel)
        {
            var geospatialAreaTypeSimples = HttpRequestStorage.DatabaseEntities.GeospatialAreaTypes.ToList().Select(x => new GeospatialAreaTypeSimple(x)).ToList();
            //build list of geospatial areas and remove any we have already setup a connection to this performance measure
            var geospatialAreaSimples = HttpRequestStorage.DatabaseEntities.vGeospatialAreas
                                        .Where(x => x.TenantID == HttpRequestStorage.DatabaseEntities.TenantID)
                                        .ToList().Select(x => new GeospatialAreaSimple(x)).ToList();//todo: probably want this data coming from an AJAX call
            var selectedGeospatialAreas       = GetSelectedGeospatialAreasFromPerformanceMeasure(performanceMeasure);
            var selectedGeospatialAreaSimples = geospatialAreaSimples.Where(x => selectedGeospatialAreas.Contains(x.GeospatialAreaID)).ToList();
            var setToRemove = new HashSet <GeospatialAreaSimple>(selectedGeospatialAreaSimples);

            geospatialAreaSimples.RemoveAll(x => setToRemove.Contains(x));

            var viewDataForAngular = new AddGeospatialAreaToPerformanceMeasureViewDataForAngular(performanceMeasure, geospatialAreaTypeSimples, geospatialAreaSimples);
            var viewData           = new AddGeospatialAreaToPerformanceMeasureViewData(performanceMeasure, viewDataForAngular);

            return(RazorPartialView <AddGeospatialAreaToPerformanceMeasure, AddGeospatialAreaToPerformanceMeasureViewData, AddGeospatialAreaToPerformanceMeasureViewModel>(viewData, viewModel));
        }
        public ActionResult AddGeospatialAreaToPerformanceMeasure(PerformanceMeasurePrimaryKey performanceMeasurePrimaryKey, AddGeospatialAreaToPerformanceMeasureViewModel viewModel)
        {
            var performanceMeasure = performanceMeasurePrimaryKey.EntityObject;

            if (!ModelState.IsValid)
            {
                return(ViewAddGeospatialAreaToPerformanceMeasure(performanceMeasure, viewModel));
            }

            viewModel.UpdateModel(CurrentFirmaSession, performanceMeasure);

            return(new ModalDialogFormJsonResult());
        }