public IActionResult AddTestToScorecard(Guid scorecardID, Guid categoryID, Guid testID) { var scorecard = _database.Scorecards.Find(scorecardID); var categoryTest = _database.CategoryTests.Find(testID); if (categoryTest != null) { var scorecardTest = ScorecardTestModel.FromCategoryTest(categoryTest, scorecardID); scorecardTest.Value = scorecard.DefaultTestValue; _database.ScorecardTests.Add(scorecardTest); _database.SaveChanges(); } return(RedirectToAction("AddScorecardTests", new { id = scorecardID, categoryID = categoryID })); }
public IActionResult AddAllCategoryTests(Guid id, Guid categoryID) { var scorecard = _database.Scorecards.Find(id); scorecard.Tests = _database.ScorecardTests.Where(t => t.ScorecardID == id).ToList(); var categoryTests = _database.CategoryTests.Where(t => t.CategoryID == categoryID).ToList(); foreach (var test in categoryTests.ToList()) { var existing = scorecard.Tests.FirstOrDefault(t => t.ID == test.ID); if (existing == null) { var scorecardTest = ScorecardTestModel.FromCategoryTest(test, scorecard.ID); _database.ScorecardTests.Add(scorecardTest); } } _database.SaveChanges(); return(RedirectToAction("ScorecardDetails", new { id = id })); }