Ejemplo n.º 1
0
        public async Task <ActionResult> Update(int id, int testprojectId, TestSession model, int[] testagents)
        {
            var project = model.Project = await _projRepo.FindAsync(testprojectId);

            var plan = model.Plan = project.Plans.FirstOrDefault(z => z.Id == model.TestPlanId);

            if (plan == null)
            {
                ModelState.AddModelError("testplan", "no test plan found for this test session");
            }
            else
            {
                if (plan.Cases.Count == 0)
                {
                    ModelState.AddModelError("testplan", "empty test plan for this test session");
                }
            }
            if (ModelState.IsValid)
            {
                _sessionRepo.Modify(model);
                if (testagents != null)
                {
                    var queueRepo = _uow.Repository <TestQueue>();
                    var q         = await(from e in queueRepo.Query()
                                          where e.Session.Id == model.Id
                                          select e).ToListAsync();
                    q.ForEach(z => queueRepo.Remove(z));

                    var agents = (from e in _agentRepo.Query()
                                  where testagents.Contains(e.Id)
                                  select e).ToList().AsReadOnly();
                    model.SetAgents(agents);
                }

                await _uow.CommitAsync();

                return(RedirectToAction("Show", new { id, testprojectId }));
            }
            SetNav(model);
            SetViewData();
            return(View("edit", model));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Create(int testprojectId, TestSession model, int[] testagents)
        {
            var project = model.Project = await _projRepo.FindAsync(testprojectId);

            var plan = model.Plan = project.Plans.FirstOrDefault(z => z.Id == model.TestPlanId);

            if (plan == null)
            {
                ModelState.AddModelError("testplan", "no test plan found for this test session");
            }
            else
            {
                if (plan.Cases.Count == 0)
                {
                    ModelState.AddModelError("testplan", "empty test plan for this test session");
                }
            }

            if (ModelState.IsValid)
            {
                if (testagents != null)
                {
                    var agents = (from e in _agentRepo.Query()
                                  where testagents.Contains(e.Id)
                                  select e).ToList().AsReadOnly();
                    model.SetAgents(agents);
                }
                project.Sessions.Add(model);
                await _uow.CommitAsync();

                return(RedirectToAction("Show", new { id = model.Id, testprojectId }));
            }
            SetNav(model);
            SetViewData();
            return(View("new", model));
        }