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 async Task <ActionResult> TestGroupDetails(Guid testGroupGuid) { TestGroupRepository testGroupRepo = new TestGroupRepository(); var testGroupTask = testGroupRepo.GetByIdAsync(testGroupGuid); ApplicationUserRepository <Tester> userRepo = new ApplicationUserRepository <Tester>(); var testerTask = userRepo.GetByUserNameAsync(User.Identity.Name); TestGroupsRepository testGroupsRepo = new TestGroupsRepository(); ViewBag.Takened = testGroupsRepo.GetGroupStatus(await testGroupTask, await testerTask); ViewBag.TestsGuid = testGroupsRepo.GetByTestGroupForTester(await testerTask, await testGroupTask); return(View(await testGroupTask)); }
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 CompanyTestGroupsDataTable(IDataTablesRequest request) { ApplicationUserRepository <Company> companyRepo = new ApplicationUserRepository <Company>(); var company = companyRepo.GetByUserName(User.Identity.Name); var testGroupRepo = new TestGroupRepository(); var orderColumn = request.Columns.Where(c => c.Sort != null).First(); bool asc; if (orderColumn.Sort.Direction == 0) { asc = true; } else { asc = false; } var testGroups = testGroupRepo.GetEntitiesForCompany(out int totalCount, out int filteredCount, request.Start, request.Length, nameof(TestCase.Name), request.Search.Value, orderColumn.Name, asc, company); var resault = testGroups.Select(x => new { x.Id, x.Name, x.SkillDificulty, x.TimeDificulty, x.RewardMultiplier, x.Rating, x.Created, x.AvailableTo, testCasesCount = x.TestCases.Count }); var response = DataTablesResponse.Create(request, totalCount, filteredCount, resault); return(new DataTablesJsonResult(response, JsonRequestBehavior.DenyGet)); }
public async Task TakeGroup(Guid groupId) { TestGroupRepository testGroupRepo = new TestGroupRepository(); var testGroupTask = testGroupRepo.GetByIdAsync(groupId); ApplicationUserRepository <Tester> userRepo = new ApplicationUserRepository <Tester>(); var testerTask = userRepo.GetByUserNameAsync(User.Identity.Name); TestGroups testGroups = new TestGroups(); testGroups.TestGroup = await testGroupTask; testGroups.Status = GroupStatus.Takened; testGroups.Takened = DateTime.Now; testGroups.Tester = await testerTask; TestGroup testGroup = await testGroupTask; TestsRepository testsRepo = new TestsRepository(); foreach (var testCase in testGroup.TestCases) { if (!testsRepo.IsTestTakened(testCase, await testerTask)) { DataAccess.Model.Tests.Tests tests = new DataAccess.Model.Tests.Tests(); tests.Test = testCase; tests.Status = TestsStatus.Takened; tests.Takened = DateTime.Now; tests.Tester = await testerTask; testsRepo.Create(tests); } } TestGroupsRepository testGroupsRepo = new TestGroupsRepository(); testGroupsRepo.Create(testGroups); }
public async Task <ActionResult> TesterTestGroups(int?page, string searchTerm) { TestGroupRepository testGroupsRepo = new TestGroupRepository(); ApplicationUserRepository <Tester> userRepo = new ApplicationUserRepository <Tester>(); var testerTask = userRepo.GetByUserNameAsync(User.Identity.Name); int itemsOnPage = 8; int pg = page ?? 1; int startIndex = (pg * itemsOnPage) - itemsOnPage; ViewBag.CurrentSearch = searchTerm; IList <TestGroup> testGroups = testGroupsRepo.GetAvailableEntities(out var totalTests, await testerTask, DateTime.Today, startIndex, itemsOnPage, searchTerm); ViewBag.Pages = (int)Math.Ceiling((double)totalTests / (double)itemsOnPage); ViewBag.CurrentPage = pg; if (Request.IsAjaxRequest()) { return(PartialView(testGroups)); } return(View(testGroups)); }
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")); }
public ActionResult AddTestGroup(TestGroup testGroup, string data) { if (string.IsNullOrEmpty(data)) { TempData["error"] = "At least one test case must be selected!"; return(View("CreateTestGroup")); } 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) { ApplicationUserRepository <Company> userRepo = new ApplicationUserRepository <Company>(); Company currentUser = userRepo.GetByUserName(User.Identity.Name); var testCasesId = data.Split(','); TestCaseRepository testCaseRepo = new TestCaseRepository(); IList <TestCase> testCases = new List <TestCase>(); foreach (var testCaseId in testCasesId) { TestCase tempTestCase = testCaseRepo.GetByIdForCompanyNotInGroup(currentUser, Guid.Parse(testCaseId)); tempTestCase.IsInGroup = true; testCases.Add(tempTestCase); } DateTime latestAvailability = testCases.OrderByDescending(x => x.AvailableTo).First().AvailableTo; if (testGroup.AvailableTo < latestAvailability) { TempData["error"] = $"Available To must be equal or greater than availability of latest test case ({latestAvailability.ToShortDateString()})!"; return(View("CreateTestGroup")); } testGroup.TestCases = testCases; testGroup.SkillDificulty = testGroup.CountSkillDificulty(); testGroup.TimeDificulty = testGroup.CountTimeDificulty(); testGroup.RewardMultiplier = (testGroup.RewardMultiplier + 100) / 100; testGroup.Creator = currentUser; testGroup.Created = DateTime.Now; foreach (var testCase in testCases) { testCaseRepo.Update(testCase); } TestGroupRepository testGroupRepo = new TestGroupRepository(); testGroupRepo.Create(testGroup); TempData["success"] = "Test group was added"; } else { return(View("CreateTestGroup")); } return(RedirectToAction("CompanyTestGroups")); }
// GET: Testing/Home public async Task <ActionResult> Index() { if (User.IsInRole("company")) { ViewBag.Role = "company"; ApplicationUserRepository <Company> companyRepo = new ApplicationUserRepository <Company>(); TestCaseRepository testCaseRepo = new TestCaseRepository(); TestGroupRepository testGroupRepo = new TestGroupRepository(); DisputeRepository disputeRepo = new DisputeRepository(); Company company = companyRepo.GetByUserName(User.Identity.Name); var tests = testCaseRepo.GetCountForCompanyAsync(company); var testGroups = testGroupRepo.GetCountForCompanyAsync(company); var disputes = disputeRepo.GetCountWithCompanyAsync(company); ViewBag.Credits = company.Credits; ViewBag.Tests = await tests; ViewBag.TestGroups = await testGroups; ViewBag.Disputes = await disputes; } if (User.IsInRole("tester")) { ViewBag.Role = "tester"; ApplicationUserRepository <Tester> testerRepo = new ApplicationUserRepository <Tester>(); DisputeRepository disputeRepo = new DisputeRepository(); TestsRepository testRepo = new TestsRepository(); var tester = testerRepo.GetByUserName(User.Identity.Name); var dispute = disputeRepo.GetCountWithTesterAsync(tester); IList <TestsStatus> takened = new List <TestsStatus>(); takened.Add(TestsStatus.Takened); IList <TestsStatus> finished = new List <TestsStatus>(); finished.Add(TestsStatus.Finished); finished.Add(TestsStatus.Reviewed); ViewBag.Credits = tester.Credits; ViewBag.Disputes = await dispute; ViewBag.ResolvedTests = testRepo.GetCountByStatus(finished, tester); ViewBag.TakenedTests = testRepo.GetCountByStatus(takened, tester); } if (User.IsInRole("admin")) { ViewBag.Role = "admin"; ApplicationUserRepository <Admin> adminRepo = new ApplicationUserRepository <Admin>(); DisputeRepository disputeRepo1 = new DisputeRepository(); DisputeRepository disputeRepo2 = new DisputeRepository(); DisputeRepository disputeRepo3 = new DisputeRepository(); SoftwareTypeRepository swTypeRepo = new SoftwareTypeRepository(); TestCaseRepository testCatRepo = new TestCaseRepository(); Admin admin = adminRepo.GetByUserName(User.Identity.Name); var disputes = disputeRepo1.GetCountPandingAsync(); var inProgressDisputes = disputeRepo2.GetCountForAdminInProgressAsync(admin); var resolvedDisputes = disputeRepo3.GetCountForAdminResolvedAsync(admin); var admins = adminRepo.GetCountAsync(); var softwareTypes = swTypeRepo.GetCountAsync(); var testCategories = testCatRepo.GetCountAsync(); ViewBag.Disputes = await disputes; ViewBag.InProgressDisputes = await inProgressDisputes; ViewBag.ResolvedDisputes = await resolvedDisputes; ViewBag.Admins = await admins; ViewBag.SoftwareTypes = await softwareTypes; ViewBag.TestCategories = await testCategories; } return(View()); }