Esempio n. 1
0
        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() }));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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());
        }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
        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"));
        }