public ActionResult DeleteAttachment(string id, string attachment) { TestCaseRepository testCaseRepo = new TestCaseRepository(); EvidenceRepository evidenceRepo = new EvidenceRepository(); TestCase testCase = testCaseRepo.GetById(Guid.Parse(id)); if (testCase.Evidences != null && testCase.Evidences.Count > 0) { foreach (var evidence in testCase.Evidences) { if (evidence.Id == Guid.Parse(attachment)) { System.IO.File.Delete(Server.MapPath("~/Uploads/" + evidence.Name + evidence.Extension)); evidenceRepo.Delete(evidence); } } } SoftwareTypeRepository swTypeRepo = new SoftwareTypeRepository(); IList <SoftwareType> swTypes = swTypeRepo.GetAllValid(); ViewBag.SoftwareTypes = swTypes; TestCategoryRepository testCatRepo = new TestCategoryRepository(); IList <TestCategory> testCats = testCatRepo.GetAllValid(); ViewBag.TestCategories = testCats; return(RedirectToAction("EditTestCase", "Tests", new { id = testCase.Id.ToString() })); }
public CategoryManagerTest() { var testRepo = new TestCategoryRepository(); var validator = new CategoryValidator(); _mng = new CategoryManager(testRepo, validator); }
public async Task <ActionResult> UpdateTestCategory(TestCategory testCat) { ModelState.Remove(nameof(testCat.Id)); ModelState.Remove(nameof(testCat.Created)); ModelState.Remove(nameof(testCat.LastChange)); ModelState.Remove(nameof(testCat.ChangedBy)); if (ModelState.IsValid) { var userRepository = new ApplicationUserRepository <Admin>(); var testCatRepo = new TestCategoryRepository(); var currentUser = userRepository.GetByUserNameAsync(User.Identity.Name); testCat.LastChange = DateTime.Now; testCat.ChangedBy = await currentUser; testCatRepo.Update(testCat); TempData["success"] = "Test category was edited"; } else { return(View("EditTestCategory", testCat)); } return(RedirectToAction("TestCategories")); }
public ActionResult EditTestCategory(string id) { var testCatRepo = new TestCategoryRepository(); var testCat = testCatRepo.GetById(Guid.Parse(id)); return(View(testCat)); }
public ActionResult TestCategoriesDataTable(IDataTablesRequest request) { var testCatRepo = new TestCategoryRepository(); var orderColumn = request.Columns.Where(c => c.Sort != null).First(); bool asc; if (orderColumn.Sort.Direction == 0) { asc = true; } else { asc = false; } var testCat = testCatRepo.GetEntities(out int totalCount, out int filteredCount, request.Start, request.Length, nameof(SoftwareType.Name), request.Search.Value, orderColumn.Name, asc).Select(x => new { x.Id, x.Name, x.Description, x.Valid, x.Created, x.LastChange, x.ChangedBy, ChangedByName = x.ChangedBy.FirstName + " " + x.ChangedBy.LastName }); var response = DataTablesResponse.Create(request, totalCount, filteredCount, testCat); return(new DataTablesJsonResult(response, JsonRequestBehavior.DenyGet)); }
public ActionResult FinishedTests(int?page, Guid?swTypeGuid, Guid?testCatGuid, string searchTerm) { TestsRepository testsRepo = new TestsRepository(); SoftwareTypeRepository swTypeRepo = new SoftwareTypeRepository(); ViewBag.SoftTypes = swTypeRepo.GetAllValid(); TestCategoryRepository testCatRepo = new TestCategoryRepository(); ViewBag.TestCategories = testCatRepo.GetAllValid(); ApplicationUserRepository <Tester> userRepo = new ApplicationUserRepository <Tester>(); Tester tester = userRepo.GetByUserName(User.Identity.Name); int itemsOnPage = 8; int pg = page ?? 1; int startIndex = (pg * itemsOnPage) - itemsOnPage; SoftwareType swType = null; if (swTypeGuid != null) { swType = swTypeRepo.GetById((Guid)swTypeGuid); ViewBag.SoftType = swType; } TestCategory testCat = null; if (testCatGuid != null) { testCat = testCatRepo.GetById((Guid)testCatGuid); ViewBag.TestCategory = testCat; } ViewBag.CurrentSearch = searchTerm; IList <TestsStatus> statuses = new List <TestsStatus>(); statuses.Add(TestsStatus.Finished); statuses.Add(TestsStatus.Reviewed); IList <DataAccess.Model.Tests.Tests> tests = testsRepo.GetAvailableEntities(out var totalTests, tester, statuses, swType, testCat, startIndex, itemsOnPage, searchTerm); ViewBag.Pages = (int)Math.Ceiling((double)totalTests / (double)itemsOnPage); ViewBag.CurrentPage = pg; if (Request.IsAjaxRequest()) { return(PartialView(tests)); } return(View(tests)); }
public ActionResult CreateTestCase() { SoftwareTypeRepository swTypeRepo = new SoftwareTypeRepository(); IList <SoftwareType> swTypes = swTypeRepo.GetAllValid(); ViewBag.SoftwareTypes = swTypes; TestCategoryRepository testCatRepo = new TestCategoryRepository(); IList <TestCategory> testCats = testCatRepo.GetAllValid(); ViewBag.TestCategories = testCats; return(View()); }
public async Task <ActionResult> TesterTests(int?page, Guid?swTypeGuid, Guid?testCatGuid, string searchTerm) { TestCaseRepository testCaseRepo = new TestCaseRepository(); ApplicationUserRepository <Tester> userRepo = new ApplicationUserRepository <Tester>(); var testerTask = userRepo.GetByUserNameAsync(User.Identity.Name); SoftwareTypeRepository swTypeRepo = new SoftwareTypeRepository(); ViewBag.SoftTypes = swTypeRepo.GetAllValid(); TestCategoryRepository testCatRepo = new TestCategoryRepository(); ViewBag.TestCategories = testCatRepo.GetAllValid(); int itemsOnPage = 8; int pg = page ?? 1; int startIndex = (pg * itemsOnPage) - itemsOnPage; SoftwareType swType = null; if (swTypeGuid != null) { swType = swTypeRepo.GetById((Guid)swTypeGuid); ViewBag.SoftType = swType; } TestCategory testCat = null; if (testCatGuid != null) { testCat = testCatRepo.GetById((Guid)testCatGuid); ViewBag.TestCategory = testCat; } ViewBag.CurrentSearch = searchTerm; IList <TestCase> testCases = testCaseRepo.GetAvailableEntities(out var totalTests, DateTime.Today, await testerTask, swType, testCat, startIndex, itemsOnPage, searchTerm); ViewBag.Pages = (int)Math.Ceiling((double)totalTests / (double)itemsOnPage); ViewBag.CurrentPage = pg; if (Request.IsAjaxRequest()) { return(PartialView(testCases)); } return(View(testCases)); }
public ActionResult DetailTestCaseCompany(string id) { SoftwareTypeRepository swTypeRepo = new SoftwareTypeRepository(); IList <SoftwareType> swTypes = swTypeRepo.GetAllValid(); ViewBag.SoftwareTypes = swTypes; TestCategoryRepository testCatRepo = new TestCategoryRepository(); IList <TestCategory> testCats = testCatRepo.GetAllValid(); ViewBag.TestCategories = testCats; var testCaseRepo = new TestCaseRepository(); var testCase = testCaseRepo.GetById(Guid.Parse(id)); return(View(testCase)); }
public ActionResult ToggleValidTestCategory(IList <TestCategory> rows) { var testCatRepo = new TestCategoryRepository(); foreach (var row in rows) { var testCat = testCatRepo.GetById(row.Id); if (testCat.Valid) { testCat.Valid = false; } else if (!testCat.Valid) { testCat.Valid = true; } testCatRepo.Update(testCat); } TempData["success"] = "Test category/ies was updated!"; return(View("TestCategories")); }
public ActionResult DeleteTestCategory(IList <TestCategory> rows) { var testCatRepo = new TestCategoryRepository(); foreach (var row in rows) { var testCat = testCatRepo.GetById(row.Id); try { testCatRepo.Delete(testCat); } catch (Exception e) { TempData["error"] = "Test category/ies can't be delete, because it used in some part of system!"; return(View("TestCategories")); } } TempData["success"] = "Test category/ies was deleted!"; return(View("TestCategories")); }
public async Task <ActionResult> UpdateTestCase(TestCase testCase, HttpPostedFileBase[] files) { ModelState.Remove(nameof(testCase.Evidences)); ModelState.Remove(nameof(testCase.Rating)); ModelState.Remove(nameof(testCase.Created)); ModelState.Remove(nameof(testCase.Creator)); ModelState.Remove(nameof(testCase.Reviews)); ModelState.Remove(nameof(testCase.IsInGroup)); ModelState.Remove("SoftwareType.Name"); ModelState.Remove("Category.Name"); ModelState.Remove("files"); if (ModelState.IsValid) { TestCaseRepository testCaseRepo = new TestCaseRepository(); TestCategoryRepository testCatRepo = new TestCategoryRepository(); SoftwareTypeRepository swTypeRepo = new SoftwareTypeRepository(); TestCase oldTestCase = testCaseRepo.GetById(testCase.Id); IList <Evidence> evidences = new List <Evidence>(); if (testCase.AvailableTo <= DateTime.Now) { IList <SoftwareType> swTypes = swTypeRepo.GetAllValid(); IList <TestCategory> testCats = testCatRepo.GetAllValid(); ViewBag.SoftwareTypes = swTypes; ViewBag.TestCategories = testCats; TempData["error"] = "Available To must be in future!"; return(View("EditTestCase", testCase)); } if (files[0] != null) { if (oldTestCase.Evidences == null || oldTestCase.Evidences.Count <= 0) { oldTestCase.Evidences = new List <Evidence>(); } var maxSizeInMb = 20; var byteSize = 1048576; var maxSizeInBytes = byteSize * maxSizeInMb; foreach (var file in files) { if (file.ContentLength > maxSizeInBytes) { IList <SoftwareType> swTypes = swTypeRepo.GetAllValid(); IList <TestCategory> testCats = testCatRepo.GetAllValid(); ViewBag.SoftwareTypes = swTypes; ViewBag.TestCategories = testCats; TempData["error"] = "File " + file.FileName + " is too big! (max size is " + maxSizeInMb + "MB)"; return(View("EditTestCase", testCase)); } } foreach (var file in files) { Evidence evidence = new Evidence(); evidence.Id = Guid.NewGuid(); evidence.Name = evidence.Id.ToString(); evidence.RealName = Path.GetFileNameWithoutExtension(file.FileName); evidence.Attached = DateTime.Now; var extension = Path.GetExtension(file.FileName); evidence.Extension = extension; var path = Path.Combine(Server.MapPath("~/Uploads"), evidence.Name + extension); Directory.CreateDirectory(Server.MapPath("~/Uploads")); file.SaveAs(path); oldTestCase.Evidences.Add(evidence); evidences.Add(evidence); } } var swType = swTypeRepo.GetByIdAsync(testCase.SoftwareType.Id); var testCat = testCatRepo.GetByIdAsync(testCase.Category.Id); oldTestCase.SoftwareType = await swType; oldTestCase.Category = await testCat; oldTestCase.Name = testCase.Name; oldTestCase.SkillDificulty = testCase.SkillDificulty; oldTestCase.TimeDificulty = testCase.TimeDificulty; oldTestCase.AvailableTo = testCase.AvailableTo; oldTestCase.Description = testCase.Description; oldTestCase.Reward = testCase.Reward; EvidenceRepository evidRepo = new EvidenceRepository(); foreach (var evidence in evidences) { evidRepo.Create(evidence); } testCaseRepo.Update(oldTestCase); TempData["success"] = "Test case was edited"; } else { SoftwareTypeRepository swTypeRepo = new SoftwareTypeRepository(); IList <SoftwareType> swTypes = swTypeRepo.GetAllValid(); ViewBag.SoftwareTypes = swTypes; TestCategoryRepository testCatRepo = new TestCategoryRepository(); IList <TestCategory> testCats = testCatRepo.GetAllValid(); ViewBag.TestCategories = testCats; if (!swTypeRepo.IsSwTypeExist(testCase.SoftwareType.Id)) { TempData["error"] = "Please select Software type!"; return(View("EditTestCase", testCase)); } if (!testCatRepo.IsTestCatExist(testCase.Category.Id)) { TempData["error"] = "Please select Category!"; return(View("EditTestCase", testCase)); } return(View("EditTestCase", testCase)); } return(RedirectToAction("CompanyTests")); }