Ejemplo n.º 1
0
        public async Task <TestCase> AddAsync(AddTestCaseParams ps)
        {
            var sibingsCount = await _context.TestNodes.CountAsync(tn => tn.ParentId == ps.ParentId);

            ps.Position = ps.Position <= -1 ? sibingsCount : Math.Min(ps.Position, sibingsCount);

            foreach (var node in _context.TestNodes.Where(tn =>
                                                          tn.ParentId == ps.ParentId && tn.Position >= ps.Position))
            {
                node.Position++;
            }

            var testCase = _mapper.Map <TestCase>(ps);

            testCase.Count = 1;

            await _context.TextCases.AddAsync(testCase);

            // calc count
            var ancestors = new List <TestNode>();

            ancestors.Add(await _nodeService.GetAsync(ps.ParentId));
            ancestors.AddRange(await _nodeService.GetAncestorsAsync(ps.ParentId));

            foreach (var ancestor in ancestors)
            {
                ancestor.Count++;
            }

            await _context.SaveChangesAsync();

            return(testCase);
        }
Ejemplo n.º 2
0
        public async Task DeleteAsync(int id)
        {
            var testSuite = await GetAsync(id);

            foreach (var node in _context.TestNodes.Where(tn =>
                                                          tn.ParentId == testSuite.ParentId && tn.Position > testSuite.Position))
            {
                node.Position--;
            }

            testSuite.IsDeleted = true;
            (await _nodeService.GetDescendantsAsync(id)).ForEach(tn => tn.IsDeleted = true);

            // calc count
            foreach (var ancestor in await _nodeService.GetAncestorsAsync(id))
            {
                ancestor.Count -= testSuite.Count;
            }

            await _context.SaveChangesAsync();
        }