public ActionResult Edit(TaxonomyLeafPrimaryKey taxonomyLeafPrimaryKey, EditViewModel viewModel) { var taxonomyLeaf = taxonomyLeafPrimaryKey.EntityObject; if (!ModelState.IsValid) { return(ViewEdit(viewModel, taxonomyLeaf.TaxonomyBranch.GetDisplayName())); } viewModel.UpdateModel(taxonomyLeaf, CurrentFirmaSession); return(new ModalDialogFormJsonResult()); }
public void UpdateModelTest() { // Arrange var taxonomyLeaf = TestFramework.TestTaxonomyLeaf.Create(); var viewModel = new EditViewModel(taxonomyLeaf); viewModel.TaxonomyLeafName = TestFramework.MakeTestName(GeneralUtility.NameOf(() => viewModel.TaxonomyLeafName), ProjectFirmaModels.Models.TaxonomyLeaf.FieldLengths.TaxonomyLeafName); // Act viewModel.UpdateModel(taxonomyLeaf, TestFramework.TestFirmaSession.Create()); // Assert Assert.That(taxonomyLeaf.TaxonomyLeafName, Is.EqualTo(viewModel.TaxonomyLeafName)); }
public ActionResult New(EditViewModel viewModel) { if (!ModelState.IsValid) { return(ViewNew(viewModel)); } var taxonomyLeaf = new TaxonomyLeaf(viewModel.TaxonomyBranchID, string.Empty); viewModel.UpdateModel(taxonomyLeaf, CurrentFirmaSession); HttpRequestStorage.DatabaseEntities.AllTaxonomyLeafs.Add(taxonomyLeaf); HttpRequestStorage.DatabaseEntities.SaveChanges(); // we need to add this new leaf as a TaxonomyLeafPerformanceMeasure 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.TaxonomyLeafs.Where(x => x.TaxonomyBranchID == taxonomyLeaf.TaxonomyBranchID).Select(x => x.TaxonomyLeafID).ToList(); var taxonomyLeafPerformanceMeasuresGroupedByPerformanceMeasure = HttpRequestStorage.DatabaseEntities.TaxonomyLeafPerformanceMeasures .Where(x => leaves.Contains(x.TaxonomyLeafID)).ToList().GroupBy(x => x.PerformanceMeasure, new HavePrimaryKeyComparer <PerformanceMeasure>()); var taxonomyLeafPerformanceMeasures = taxonomyLeafPerformanceMeasuresGroupedByPerformanceMeasure.Select(x => new TaxonomyLeafPerformanceMeasure(taxonomyLeaf, x.Key)); } else if (associatePerformanceMeasureTaxonomyLevel == TaxonomyLevel.Trunk) { var taxonomyBranch = HttpRequestStorage.DatabaseEntities.TaxonomyBranches.GetTaxonomyBranch(taxonomyLeaf.TaxonomyBranchID); var leaves = taxonomyBranch.TaxonomyTrunk.TaxonomyBranches.SelectMany(x => x.TaxonomyLeafs.Select(y => y.TaxonomyLeafID)).ToList(); var taxonomyLeafPerformanceMeasuresGroupedByPerformanceMeasure = HttpRequestStorage.DatabaseEntities.TaxonomyLeafPerformanceMeasures .Where(x => leaves.Contains(x.TaxonomyLeafID)).ToList().GroupBy(x => x.PerformanceMeasure, new HavePrimaryKeyComparer <PerformanceMeasure>()); var taxonomyLeafPerformanceMeasures = taxonomyLeafPerformanceMeasuresGroupedByPerformanceMeasure.Select(x => new TaxonomyLeafPerformanceMeasure(taxonomyLeaf, x.Key)); } SetMessageForDisplay($"New {FieldDefinitionEnum.TaxonomyLeaf.ToType().GetFieldDefinitionLabel()} {taxonomyLeaf.GetDisplayNameAsUrl()} successfully created!"); return(new ModalDialogFormJsonResult()); }