Ejemplo n.º 1
0
        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() }));
        }
Ejemplo n.º 2
0
        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"));
        }
Ejemplo n.º 3
0
        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"));
        }