Beispiel #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() }));
        }
Beispiel #2
0
        public ActionResult DeleteTestCase(IList <TestCase> rows)
        {
            var testCaseRepo = new TestCaseRepository();

            foreach (var row in rows)
            {
                var testCase = testCaseRepo.GetById(row.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 case/s was deleted!";

            return(View("CompanyTests"));
        }
        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 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"));
        }
Beispiel #5
0
        public ActionResult TestsResaults(int?page, Guid?testCaseGuid, Guid?statusGuid)
        {
            TestsRepository testsRepo = new TestsRepository();

            ApplicationUserRepository <Company> userRepo = new ApplicationUserRepository <Company>();
            Company company = userRepo.GetByUserName(User.Identity.Name);

            TestCaseRepository testCaseRepo = new TestCaseRepository();

            ViewBag.TestCases = testCaseRepo.GetAllForCompany(company);

            TestStatusRepository statusRepo = new TestStatusRepository();

            ViewBag.Statuses = statusRepo.GetAll();

            int itemsOnPage = 20;
            int pg          = page ?? 1;
            int startIndex  = (pg * itemsOnPage) - itemsOnPage;

            TestCase testCase = null;

            if (testCaseGuid != null)
            {
                testCase         = testCaseRepo.GetById((Guid)testCaseGuid);
                ViewBag.TestCase = testCase;
            }

            TestStatus testStatus = null;

            if (statusGuid != null)
            {
                testStatus     = statusRepo.GetById((Guid)statusGuid);
                ViewBag.Status = testStatus;
            }

            IList <DataAccess.Model.Tests.Tests> testses = testsRepo.GetTestsForCompany(company, out int totalTests, out int filteredCount, testCase, testStatus, startIndex, itemsOnPage);

            ViewBag.Pages       = (int)Math.Ceiling((double)totalTests / (double)itemsOnPage);
            ViewBag.CurrentPage = pg;

            if (Request.IsAjaxRequest())
            {
                return(PartialView(testses));
            }

            return(View(testses));
        }
Beispiel #6
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));
        }
Beispiel #7
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"));
        }