Example #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() }));
        }
        public async Task <ActionResult> UpdateSoftwareType(SoftwareType swType)
        {
            ModelState.Remove(nameof(swType.Id));
            ModelState.Remove(nameof(swType.Created));
            ModelState.Remove(nameof(swType.LastChange));
            ModelState.Remove(nameof(swType.ChangedBy));
            if (ModelState.IsValid)
            {
                var userRepository = new ApplicationUserRepository <Admin>();
                var swTypeRepo     = new SoftwareTypeRepository();
                var currentUser    = userRepository.GetByUserNameAsync(User.Identity.Name);

                swType.LastChange = DateTime.Now;
                swType.ChangedBy  = await currentUser;

                swTypeRepo.Update(swType);
                TempData["success"] = "Software type was edited";
            }
            else
            {
                return(View("EditSoftwareType", swType));
            }

            return(RedirectToAction("SoftwareTypes"));
        }
        public ActionResult EditSoftwareType(string id)
        {
            var swTypeRepo = new SoftwareTypeRepository();
            var swType     = swTypeRepo.GetById(Guid.Parse(id));

            return(View(swType));
        }
        public ActionResult SoftwareTypesDataTable(IDataTablesRequest request)
        {
            var swTypeRepo = new SoftwareTypeRepository();

            var orderColumn = request.Columns.Where(c => c.Sort != null).First();

            bool asc;

            if (orderColumn.Sort.Direction == 0)
            {
                asc = true;
            }
            else
            {
                asc = false;
            }

            var swTypes = swTypeRepo.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, swTypes);

            return(new DataTablesJsonResult(response, JsonRequestBehavior.DenyGet));
        }
Example #5
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));
        }
Example #6
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());
        }
Example #7
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));
        }
Example #8
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));
        }
        public ActionResult ToggleValidSoftwareType(IList <SoftwareType> rows)
        {
            var swTypeRepo = new SoftwareTypeRepository();

            foreach (var row in rows)
            {
                var swType = swTypeRepo.GetById(row.Id);

                if (swType.Valid)
                {
                    swType.Valid = false;
                }
                else if (!swType.Valid)
                {
                    swType.Valid = true;
                }

                swTypeRepo.Update(swType);
            }

            TempData["success"] = "Software type/s was updated!";

            return(View("SoftwareTypes"));
        }
        public ActionResult DeleteSoftwareType(IList <SoftwareType> rows)
        {
            var swTypeRepo = new SoftwareTypeRepository();

            foreach (var row in rows)
            {
                var swType = swTypeRepo.GetById(row.Id);

                try
                {
                    swTypeRepo.Delete(swType);
                }
                catch (Exception e)
                {
                    TempData["error"] = "Software type/s can't be delete, because it used in some part of system!";

                    return(View("SoftwareTypes"));
                }
            }

            TempData["success"] = "Software type/s was deleted!";

            return(View("SoftwareTypes"));
        }
Example #11
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"));
        }
Example #12
0
        // 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());
        }