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 PartialViewResult EditProjectGeospatialAreas(ProjectPrimaryKey projectPrimaryKey, GeospatialAreaTypePrimaryKey geospatialAreaTypePrimaryKey)
        {
            var project             = projectPrimaryKey.EntityObject;
            var geospatialAreaType  = geospatialAreaTypePrimaryKey.EntityObject;
            var geospatialAreaIDs   = project.ProjectGeospatialAreas.Where(x => x.GeospatialArea.GeospatialAreaType == geospatialAreaType).Select(x => x.GeospatialAreaID).ToList();
            var geospatialAreaNotes = project.ProjectGeospatialAreaTypeNotes.SingleOrDefault(x => x.GeospatialAreaTypeID == geospatialAreaType.GeospatialAreaTypeID)?.Notes;
            var viewModel           = new EditProjectGeospatialAreasViewModel(geospatialAreaIDs, geospatialAreaNotes);

            return(ViewEditProjectGeospatialAreas(viewModel, project, geospatialAreaType));
        }
Esempio n. 3
0
        /// <summary>
        /// Method to check whether each section in a proposal is complete
        ///
        /// </summary>
        /// <param name="project"></param>
        /// <param name="geospatialAreaTypes">Geospatial areas are defined per tenant, this is passed to check if the tenant has any and are complete</param>
        public ProposalSectionsStatus(ProjectFirmaModels.Models.Project project, List <GeospatialAreaType> geospatialAreaTypes, FirmaSession currentFirmaSession)
        {
            // Basics section
            var basicsResults = new BasicsViewModel(project).GetValidationResults();

            IsBasicsSectionComplete = !basicsResults.Any();

            // Custom Attributes section
            var customAttributesValidationResults = project.ValidateCustomAttributes(currentFirmaSession).GetWarningMessages();

            IsProjectCustomAttributesSectionComplete = !customAttributesValidationResults.Any();

            // Project Location simple section
            var locationSimpleValidationResults = new LocationSimpleViewModel(project).GetValidationResults();

            IsProjectLocationSimpleSectionComplete = !locationSimpleValidationResults.Any();

            // Project location detailed section
            IsProjectLocationDetailedSectionComplete = IsBasicsSectionComplete;

            // Geospatial Area section
            if (geospatialAreaTypes.Any())
            {
                var isGeospatialAreaSectionComplete = true;
                foreach (var geospatialAreaType in geospatialAreaTypes)
                {
                    var geospatialAreaIDs = project.ProjectGeospatialAreas.Where(x => x.GeospatialArea.GeospatialAreaTypeID == geospatialAreaType.GeospatialAreaTypeID).Select(x => x.GeospatialAreaID).ToList();
                    var editGeospatialAreaValidationResults = new EditProjectGeospatialAreasViewModel(geospatialAreaIDs, project.ProjectGeospatialAreaTypeNotes.SingleOrDefault(x => x.GeospatialAreaTypeID == geospatialAreaType.GeospatialAreaTypeID)?.Notes).GetValidationResults();
                    if (editGeospatialAreaValidationResults.Any())
                    {
                        isGeospatialAreaSectionComplete = false;
                        break;
                    }
                }

                IsGeospatialAreaSectionComplete = isGeospatialAreaSectionComplete;
            }
            else
            {
                IsGeospatialAreaSectionComplete = true;
            }

            // Performance Measure section
            IsPerformanceMeasureSectionComplete = IsBasicsSectionComplete;

            // Project FundingSource Budget and Cost Type section
            var calendarYearRange = project.CalculateCalendarYearRangeForBudgetsWithoutAccountingForExistingYears();
            var allProjectRelevantCostTypesAsSimples = project.GetAllProjectRelevantCostTypesAsSimples(ProjectRelevantCostTypeGroup.Budgets);
            var budgetValidationResults =
                new EditProjectFundingSourceBudgetByCostTypeViewModel(project, calendarYearRange,
                                                                      allProjectRelevantCostTypesAsSimples).GetValidationResults();

            IsExpectedFundingSectionComplete = !budgetValidationResults.Any();

            // Classifications section
            var proposalClassificationSimples   = ProjectCreateController.GetProjectClassificationSimples(project);
            var classificationValidationResults = new EditProposalClassificationsViewModel(proposalClassificationSimples, project).GetValidationResults();

            IsClassificationsComplete = !classificationValidationResults.Any();

            // Assessment section
            IsAssessmentComplete = ProjectCreateController.GetProjectAssessmentQuestionSimples(project).All(simple => simple.Answer.HasValue);

            // Notes section
            IsNotesSectionComplete = IsBasicsSectionComplete; //there is no validation required on Notes
        }
        public ActionResult EditProjectGeospatialAreas(ProjectPrimaryKey projectPrimaryKey, GeospatialAreaTypePrimaryKey geospatialAreaTypePrimaryKey, EditProjectGeospatialAreasViewModel viewModel)
        {
            var project            = projectPrimaryKey.EntityObject;
            var geospatialAreaType = geospatialAreaTypePrimaryKey.EntityObject;

            if (!ModelState.IsValid)
            {
                return(ViewEditProjectGeospatialAreas(viewModel, project, geospatialAreaType));
            }

            var currentProjectGeospatialAreas = project.ProjectGeospatialAreas.Where(x => x.GeospatialArea.GeospatialAreaTypeID == geospatialAreaType.GeospatialAreaTypeID).ToList();
            var allProjectGeospatialAreas     = HttpRequestStorage.DatabaseEntities.AllProjectGeospatialAreas.Local;

            viewModel.UpdateModel(project, currentProjectGeospatialAreas, allProjectGeospatialAreas);
            var projectGeospatialAreaTypeNote = project.ProjectGeospatialAreaTypeNotes.SingleOrDefault(x => x.GeospatialAreaTypeID == geospatialAreaType.GeospatialAreaTypeID);

            if (!string.IsNullOrWhiteSpace(viewModel.ProjectGeospatialAreaNotes))
            {
                if (projectGeospatialAreaTypeNote == null)
                {
                    projectGeospatialAreaTypeNote = new ProjectGeospatialAreaTypeNote(project, geospatialAreaType, viewModel.ProjectGeospatialAreaNotes);
                }
                projectGeospatialAreaTypeNote.Notes = viewModel.ProjectGeospatialAreaNotes;
            }
            else
            {
                projectGeospatialAreaTypeNote?.DeleteFull(HttpRequestStorage.DatabaseEntities);
            }
            SetMessageForDisplay($"{FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} {geospatialAreaType.GeospatialAreaTypeNamePluralized} were successfully saved.");

            return(new ModalDialogFormJsonResult());
        }