public ActionResult DeleteAttachedTestCase(string id, string testCaseId) { TestGroupRepository testGroupRepo = new TestGroupRepository(); TestCaseRepository testCaseRepo = new TestCaseRepository(); TestGroup testGroup = testGroupRepo.GetById(Guid.Parse(id)); if (testGroup.TestCases != null && testGroup.TestCases.Count > 0) { foreach (var tempTestCase in testGroup.TestCases) { if (tempTestCase.Id == Guid.Parse(testCaseId)) { testGroup.TestCases.Remove(tempTestCase); break; } } testGroup.SkillDificulty = testGroup.CountSkillDificulty(); testGroup.TimeDificulty = testGroup.CountTimeDificulty(); testGroupRepo.Update(testGroup); TestCase testCase = testCaseRepo.GetById(Guid.Parse(testCaseId)); testCase.IsInGroup = false; testCaseRepo.Update(testCase); } return(RedirectToAction("EditTestGroup", "TestGroups", new { id = testGroup.Id.ToString() })); }
public ActionResult EditTestGroup(string id) { var testGroupRepo = new TestGroupRepository(); var testGroup = testGroupRepo.GetById(Guid.Parse(id)); return(View(testGroup)); }
public ActionResult DeleteTestGroupAll(IList <TestGroup> rows) { IList <Guid> testCasesId = new List <Guid>(); foreach (var row in rows) { var testGroupRepo = new TestGroupRepository(); TestGroup testGroup = testGroupRepo.GetById(row.Id); foreach (var testCase in testGroup.TestCases) { testCase.IsInGroup = false; testCasesId.Add(testCase.Id); } testGroupRepo.Update(testGroup); testGroupRepo.Delete(testGroup); } TestCaseRepository testCaseRepo = new TestCaseRepository(); foreach (var id in testCasesId) { TestCase testCase = testCaseRepo.GetById(id); if (testCase.Evidences != null && testCase.Evidences.Count > 0) { var evidenceRepo = new EvidenceRepository(); foreach (var evidence in testCase.Evidences) { System.IO.File.Delete(Server.MapPath("~/Uploads/" + evidence.Name + evidence.Extension)); evidenceRepo.Delete(evidence); } } if (testCase.Reviews != null && testCase.Reviews.Count > 0) { var reviewsRepo = new ReviewRepository(); foreach (var review in testCase.Reviews) { reviewsRepo.Delete(review); } } testCaseRepo.Delete(testCase); } TempData["success"] = "Test group/s and tests was deleted!"; return(View("CompanyTestGroups")); }
public ActionResult DeleteTestGroup(IList <TestGroup> rows) { foreach (var row in rows) { var testGroupRepo = new TestGroupRepository(); TestGroup testGroup = testGroupRepo.GetById(row.Id); foreach (var testCase in testGroup.TestCases) { testCase.IsInGroup = false; } testGroupRepo.Update(testGroup); testGroupRepo.Delete(testGroup); } TempData["success"] = "Test group/s was deleted!"; return(View("CompanyTestGroups")); }
public ActionResult UpdateTestGroup(TestGroup testGroup, string data) { TestGroupRepository testGroupRepo = new TestGroupRepository(); TestGroup oldTestGroup = testGroupRepo.GetById(testGroup.Id); if (string.IsNullOrEmpty(data) && oldTestGroup.TestCases.Count <= 0) { TempData["error"] = "At least one test case must be selected!"; return(View("EditTestGroup", testGroup)); } ModelState.Remove(nameof(TestGroup.TestCases)); ModelState.Remove(nameof(TestGroup.Created)); ModelState.Remove(nameof(TestGroup.Creator)); ModelState.Remove(nameof(TestGroup.Rating)); ModelState.Remove(nameof(TestGroup.TimeDificulty)); ModelState.Remove(nameof(TestGroup.SkillDificulty)); if (ModelState.IsValid) { var testCasesId = data.Split(','); TestCaseRepository testCaseRepo = new TestCaseRepository(); IList <TestCase> testCases = new List <TestCase>(); if (!testCasesId[0].IsNullOrEmpty()) { foreach (var testCaseId in testCasesId) { TestCase tempTestCase = testCaseRepo.GetByIdForCompanyNotInGroup(testGroup.Creator, Guid.Parse(testCaseId)); tempTestCase.IsInGroup = true; oldTestGroup.TestCases.Add(tempTestCase); testCases.Add(tempTestCase); } } DateTime latestAvailability = oldTestGroup.TestCases.OrderByDescending(x => x.AvailableTo).First().AvailableTo; if (testGroup.AvailableTo < latestAvailability) { testGroup.TestCases = oldTestGroup.TestCases; testGroup.RewardMultiplier = oldTestGroup.RewardMultiplier; TempData["error"] = $"Available To must be equal or greater than availability of latest test case ({latestAvailability.ToShortDateString()})!"; return(View("EditTestGroup", testGroup)); } oldTestGroup.SkillDificulty = oldTestGroup.CountSkillDificulty(); oldTestGroup.TimeDificulty = oldTestGroup.CountTimeDificulty(); oldTestGroup.RewardMultiplier = (testGroup.RewardMultiplier + 100) / 100; oldTestGroup.Name = testGroup.Name; oldTestGroup.AvailableTo = testGroup.AvailableTo; foreach (var testCase in testCases) { testCaseRepo.Update(testCase); } testGroupRepo.Update(oldTestGroup); TempData["success"] = "Test group was edited"; } else { return(View("CreateTestGroup")); } return(RedirectToAction("CompanyTestGroups")); }