public ActionResult Edit(ProjectTypePrimaryKey projectTypePrimaryKey, EditViewModel viewModel) { var projectType = projectTypePrimaryKey.EntityObject; if (!ModelState.IsValid) { return(ViewEdit(viewModel, projectType.TaxonomyBranch.DisplayName)); } viewModel.UpdateModel(projectType, CurrentPerson); return(new ModalDialogFormJsonResult()); }
public ActionResult New(EditViewModel viewModel) { if (!ModelState.IsValid) { return(ViewNew(viewModel)); } var projectType = new ProjectType(viewModel.TaxonomyBranchID, string.Empty, false); viewModel.UpdateModel(projectType, CurrentPerson); HttpRequestStorage.DatabaseEntities.ProjectTypes.Add(projectType); HttpRequestStorage.DatabaseEntities.SaveChanges(); // we need to add this new leaf as a ProjectTypePerformanceMeasure record if it's branch or trunk are currently associated to a PM var associatePerformanceMeasureTaxonomyLevel = MultiTenantHelpers.GetAssociatePerformanceMeasureTaxonomyLevel(); if (associatePerformanceMeasureTaxonomyLevel == TaxonomyLevel.Branch) { var leaves = HttpRequestStorage.DatabaseEntities.ProjectTypes.Where(x => x.TaxonomyBranchID == projectType.TaxonomyBranchID).Select(x => x.ProjectTypeID).ToList(); var projectTypePerformanceMeasuresGroupedByPerformanceMeasure = HttpRequestStorage.DatabaseEntities.ProjectTypePerformanceMeasures .Where(x => leaves.Contains(x.ProjectTypeID)).ToList().GroupBy(x => x.PerformanceMeasure, new HavePrimaryKeyComparer <PerformanceMeasure>()); var projectTypePerformanceMeasures = projectTypePerformanceMeasuresGroupedByPerformanceMeasure.Select(x => new ProjectTypePerformanceMeasure(projectType, x.Key, x.First().IsPrimaryProjectType)); } else if (associatePerformanceMeasureTaxonomyLevel == TaxonomyLevel.Trunk) { var taxonomyBranch = HttpRequestStorage.DatabaseEntities.TaxonomyBranches.GetTaxonomyBranch(projectType.TaxonomyBranchID); var leaves = taxonomyBranch.TaxonomyTrunk.TaxonomyBranches.SelectMany(x => x.ProjectTypes.Select(y => y.ProjectTypeID)).ToList(); var projectTypePerformanceMeasuresGroupedByPerformanceMeasure = HttpRequestStorage.DatabaseEntities.ProjectTypePerformanceMeasures .Where(x => leaves.Contains(x.ProjectTypeID)).ToList().GroupBy(x => x.PerformanceMeasure, new HavePrimaryKeyComparer <PerformanceMeasure>()); var projectTypePerformanceMeasures = projectTypePerformanceMeasuresGroupedByPerformanceMeasure.Select(x => new ProjectTypePerformanceMeasure(projectType, x.Key, x.First().IsPrimaryProjectType)); } SetMessageForDisplay($"New {FieldDefinition.ProjectType.GetFieldDefinitionLabel()} {projectType.GetDisplayNameAsUrl()} successfully created!"); return(new ModalDialogFormJsonResult()); }