private ScenarioPoint AddPoint(ScenarioDetail scenarioDetail, IEnumerable<RiskFactorDimension> riskFactorDimensions) { ScenarioPoint scenarioPoint = new ScenarioPoint(); scenarioPoint.Default(Context.UserName); scenarioDetail.ScenarioPoints.Add(scenarioPoint); foreach (RiskFactorDimension dimension in riskFactorDimensions) { ScenarioPointCoordinate coordinate = new ScenarioPointCoordinate(); coordinate.Default(Context.UserName); scenarioPoint.ScenarioPointCoordinates.Add(coordinate); coordinate.ScenarioPoint = scenarioPoint; coordinate.RiskFactorDimension = dimension; } return scenarioPoint; }
public Scenario DeepCopy(Scenario scenario, string scenarioName = "") { Scenario copyScenario = new Scenario(); Context.Scenarios.Add(copyScenario); //copy values from original and reset audit Context.Entry(copyScenario).CurrentValues.SetValues(scenario); copyScenario.Default(Context.UserName); ScenarioDetail copyDetail = new ScenarioDetail(); Context.ScenarioDetails.Add(copyDetail); Context.Entry(copyDetail).CurrentValues.SetValues(scenario.ScenarioDetail); copyDetail.Default(Context.UserName); copyDetail.Name = scenarioName; copyScenario.ScenarioDetails.Add(copyDetail); //copy locuses foreach (ScenarioLocus locus in scenario.ScenarioDetail.ScenarioLocuses.ToList()) { ScenarioLocus copyLocus = new ScenarioLocus(); Context.ScenarioLocuses.Add(copyLocus); Context.Entry(copyLocus).CurrentValues.SetValues(locus); copyLocus.Default(Context.UserName); copyDetail.ScenarioLocuses.Add(copyLocus); //copy locus dim items foreach (ScenarioLocusDimItem dimItem in locus.ScenarioLocusDimItems.ToList()) { ScenarioLocusDimItem copyDimItem = new ScenarioLocusDimItem(); Context.ScenarioLocusDimItems.Add(copyDimItem); Context.Entry(copyDimItem).CurrentValues.SetValues(dimItem); copyDimItem.Default(Context.UserName); copyLocus.ScenarioLocusDimItems.Add(copyDimItem); } //copy locus dim groups foreach (ScenarioLocusDimGroup dimGroup in locus.ScenarioLocusDimGroups.ToList()) { ScenarioLocusDimGroup copyDimGroup = new ScenarioLocusDimGroup(); Context.ScenarioLocusDimGroups.Add(copyDimGroup); Context.Entry(copyDimGroup).CurrentValues.SetValues(dimGroup); copyDimGroup.Default(Context.UserName); copyLocus.ScenarioLocusDimGroups.Add(copyDimGroup); } } //copy points foreach (ScenarioPoint point in scenario.ScenarioDetail.ScenarioPoints.ToList()) { ScenarioPoint copyPoint = new ScenarioPoint(); Context.ScenarioPoints.Add(copyPoint); Context.Entry(copyPoint).CurrentValues.SetValues(point); copyPoint.Default(Context.UserName); copyDetail.ScenarioPoints.Add(copyPoint); //copy coordinates foreach (ScenarioPointCoordinate coordinate in point.ScenarioPointCoordinates.ToList()) { ScenarioPointCoordinate copyCoordinate = new ScenarioPointCoordinate(); Context.ScenarioPointCoordinates.Add(copyCoordinate); Context.Entry(copyCoordinate).CurrentValues.SetValues(coordinate); copyCoordinate.Default(Context.UserName); copyPoint.ScenarioPointCoordinates.Add(copyCoordinate); } } //copy untis foreach (ScenarioUnit unit in scenario.ScenarioDetail.ScenarioUnits.ToList()) { ScenarioUnit copyUnit = new ScenarioUnit(); Context.ScenarioUnits.Add(copyUnit); Context.Entry(copyUnit).CurrentValues.SetValues(unit); copyUnit.Default(Context.UserName); copyDetail.ScenarioUnits.Add(copyUnit); //copy coordinates foreach (ScenarioUnitPoint unitPoint in unit.ScenarioUnitPoints.ToList()) { ScenarioUnitPoint copyUnitPoint = new ScenarioUnitPoint(); Context.ScenarioUnitPoints.Add(copyUnitPoint); Context.Entry(copyUnitPoint).CurrentValues.SetValues(unitPoint); copyUnitPoint.Default(Context.UserName); copyUnit.ScenarioUnitPoints.Add(copyUnitPoint); } } return copyScenario; }