示例#1
0
        public void RemoveOperativeParagraph(ResaOperativeParagraph paragraph)
        {
            foreach (var child in paragraph.Children)
            {
                RemoveOperativeParagraph(child);
            }
            var addAmendemts = _context.ResolutionAddAmendments
                               .Where(n => n.VirtualParagraph.ResaOperativeParagraphId == paragraph.ResaOperativeParagraphId)
                               .ToList();

            if (paragraph.Resolution != null)
            {
                paragraph.Resolution.OperativeParagraphs.Remove(paragraph);
                if (addAmendemts.Count > 0)
                {
                    foreach (var addAmendment in addAmendemts)
                    {
                        paragraph.Resolution.AddAmendments.Remove(addAmendment);
                    }
                }
            }

            if (paragraph.Parent != null)
            {
                paragraph.Parent.Children.Remove(paragraph);
            }

            var deleteSupporters = paragraph.DeleteAmendments.SelectMany(n => n.Supporters);

            _context.ResolutionAmendmentsSupporters.RemoveRange(deleteSupporters);

            var changeSupporters = paragraph.ChangeAmendments.SelectMany(n => n.Supporters);

            _context.ResolutionAmendmentsSupporters.RemoveRange(changeSupporters);

            var moveSupporters = paragraph.MoveAmendments.SelectMany(n => n.Supporters);

            _context.ResolutionAmendmentsSupporters.RemoveRange(moveSupporters);

            _context.ResolutionMoveAmendments.RemoveRange(paragraph.MoveAmendments);
            _context.ResolutionDeleteAmendments.RemoveRange(paragraph.DeleteAmendments);
            _context.ResolutionChangeAmendments.RemoveRange(paragraph.ChangeAmendments);

            _context.RemoveRange(addAmendemts);
            _context.OperativeParagraphs.Remove(paragraph);
            _context.SaveChanges();

            paragraph.MoveAmendments?.Clear();
            paragraph.DeleteAmendments?.Clear();
            paragraph.ChangeAmendments?.Clear();
            paragraph.Children?.Clear();
        }