public void AddAddAmendment(ResaElement resolution, int roleId, string newText) { _context.Update(resolution); var paragraph = new ResaOperativeParagraph() { AllowAmendments = false, IsVirtual = true, IsLocked = true, OrderIndex = resolution.OperativeParagraphs.Count, Parent = null, Resolution = resolution, Text = newText }; resolution.OperativeParagraphs.Add(paragraph); _context.OperativeParagraphs.Add(paragraph); var amendment = new ResaAddAmendment() { Resolution = resolution, Submitter = _context.Delegates.Find(roleId), VirtualParagraph = paragraph }; resolution.AddAmendments.Add(amendment); _context.ResolutionAddAmendments.Add(amendment); _context.SaveChanges(); }
public IList <ResaDeleteAmendment> GetDeleteAmendments(ResaOperativeParagraph paragraph) { return(paragraph.DeleteAmendments = _context.ResolutionDeleteAmendments .Where(n => n.TargetParagraph == paragraph) .Include(n => n.Submitter) .Include(n => n.Supporters).ThenInclude(n => n.Role) .ToList()); }
public void UpdateOperativeParagraph(ResaOperativeParagraph paragraph) { using var scope = serviceScopeFactory.CreateScope(); var resolutionService = scope.ServiceProvider.GetRequiredService <ResolutionService>(); resolutionService.UpdateOperativeParagraph(paragraph); OperativeParagraphChanged?.Invoke(this, paragraph); }
public void AddChangeAmendment(ResaOperativeParagraph paragraph, int roleId, string newText) { using var scope = serviceScopeFactory.CreateScope(); var resolutionService = scope.ServiceProvider.GetRequiredService <ResolutionService>(); resolutionService.AddChangeAmendment(paragraph, roleId, newText); OperativeParagraphChanged?.Invoke(this, paragraph); }
public void TestCanAddAnOperativeParagraph() { var paragraph = new ResaOperativeParagraph() { Resolution = resolution }; _context.OperativeParagraphs.Add(paragraph); _context.SaveChanges(); Assert.AreEqual(1, _context.OperativeParagraphs.Count(n => n.Resolution.ResaElementId == resolution.ResaElementId)); }
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(); }
public void AddRemoveAmendment(ResaOperativeParagraph paragraph, int roleId) { _context.Update(paragraph); var amendment = new ResaDeleteAmendment() { Resolution = paragraph.Resolution, Submitter = _context.Delegates.Find(roleId), TargetParagraph = paragraph }; paragraph.DeleteAmendments.Add(amendment); _context.SaveChanges(); }
public void MoveOperativeParagraphDown(ResaOperativeParagraph paragraph) { var moveUpElement = _context.OperativeParagraphs .FirstOrDefault(n => n.Resolution.ResaElementId == paragraph.Resolution.ResaElementId && n.Parent == paragraph.Parent && n.OrderIndex == paragraph.OrderIndex + 1); if (moveUpElement != null) { moveUpElement.OrderIndex--; } paragraph.OrderIndex = paragraph.OrderIndex + 1; _context.SaveChanges(); }
public ResaOperativeParagraph CreateOperativeParagraph([NotNull] ResaElement resolution, string text = "") { _context.Update(resolution); var operativeParagraph = new ResaOperativeParagraph() { Resolution = resolution, OrderIndex = _context.OperativeParagraphs.Count(n => n.Resolution.ResaElementId == resolution.ResaElementId), Text = text }; resolution.OperativeParagraphs.Add(operativeParagraph); _context.OperativeParagraphs.Add(operativeParagraph); _context.SaveChanges(); return(operativeParagraph); }
public void AddChangeAmendment(ResaOperativeParagraph paragraph, int roleId, string newText) { _context.Update(paragraph); var changeAmendment = new ResaChangeAmendment() { NewText = newText, Resolution = paragraph.Resolution, Submitter = _context.Delegates.Find(roleId), TargetParagraph = paragraph }; paragraph.ChangeAmendments.Add(changeAmendment); _context.ResolutionChangeAmendments.Add(changeAmendment); _context.SaveChanges(); }
public void TestRemoveResolutionDeletesOperativeParagraphs() { var resolution = new ResaElement(); var operativeParagraph = new ResaOperativeParagraph(); resolution.OperativeParagraphs.Add(operativeParagraph); _context.Resolutions.Add(resolution); _context.SaveChanges(); Assert.AreEqual(1, _context.Resolutions.Count()); Assert.AreEqual(1, _context.OperativeParagraphs.Count()); _context.Resolutions.Remove(resolution); _context.SaveChanges(); Assert.AreEqual(0, _context.Resolutions.Count()); Assert.AreEqual(0, _context.OperativeParagraphs.Count()); }
public void TestRemoveParentOperativeParagraphRemovesChildren() { var resolution = new ResaElement(); var operativeParagraph = new ResaOperativeParagraph(); var subParagraph = new ResaOperativeParagraph(); subParagraph.Resolution = resolution; operativeParagraph.Children.Add(subParagraph); resolution.OperativeParagraphs.Add(operativeParagraph); _context.Resolutions.Add(resolution); _context.SaveChanges(); Assert.AreEqual(1, _context.Resolutions.Count()); Assert.AreEqual(2, _context.OperativeParagraphs.Count()); _context.OperativeParagraphs.Remove(operativeParagraph); _context.SaveChanges(); Assert.AreEqual(0, _context.OperativeParagraphs.Count()); }
public static OperativeParagraph ToModel(this ResaOperativeParagraph sourceParagraph) { if (sourceParagraph.Children == null) { sourceParagraph.Children = new List <ResaOperativeParagraph>(); } var model = new OperativeParagraph() { Children = sourceParagraph.Children.Select(n => n.ToModel()).ToList(), Comment = sourceParagraph.Comment, Corrected = sourceParagraph.Corrected, IsLocked = sourceParagraph.IsLocked, IsVirtual = sourceParagraph.IsVirtual, Name = sourceParagraph.Name, OperativeParagraphId = sourceParagraph.ResaOperativeParagraphId, Text = sourceParagraph.Text, Visible = sourceParagraph.Visible }; return(model); }
public void AddMoveAmendment(ResaOperativeParagraph paragraph, int roleId, int newIndex) { _context.Update(paragraph); var virtualParagraph = new ResaOperativeParagraph() { IsVirtual = true, AllowAmendments = false, IsLocked = true, OrderIndex = newIndex, Resolution = paragraph.Resolution, Text = paragraph.Text, }; var moveAmendment = new ResaMoveAmendment() { SourceParagraph = paragraph, VirtualParagraph = virtualParagraph, Resolution = paragraph.Resolution, Submitter = _context.Delegates.Find(roleId), }; paragraph.MoveAmendments.Add(moveAmendment); _context.SaveChanges(); }
public void MoveOperativeParagraphUp(ResaOperativeParagraph paragraph) { // Make update in database using var scope = serviceScopeFactory.CreateScope(); var resolutionService = scope.ServiceProvider.GetRequiredService <ResolutionService>(); resolutionService.MoveOperativeParagraphUp(paragraph); // Make update in exchange if (paragraph.Parent == null) { var oldIndex = this.Resolution.OperativeParagraphs.IndexOf(paragraph); this.Resolution.OperativeParagraphs.Swap(oldIndex, oldIndex - 1); OperativeParagraphChanged?.Invoke(this, paragraph); ResolutionChanged?.Invoke(this, Resolution); } else { var oldIndex = paragraph.Parent.Children.IndexOf(paragraph); paragraph.Parent.Children.Swap(oldIndex, oldIndex - 1); OperativeParagraphChanged?.Invoke(this, paragraph); ResolutionChanged?.Invoke(this, Resolution); } }
public void TestRemoveOperativeParagraphRemovesMoveAmendments() { var resolution = new ResaElement(); var operativeParaph = new ResaOperativeParagraph(); resolution.OperativeParagraphs.Add(operativeParaph); var moveAmendment = new ResaMoveAmendment(); moveAmendment.SourceParagraph = operativeParaph; operativeParaph.MoveAmendments.Add(moveAmendment); _context.Resolutions.Add(resolution); _context.SaveChanges(); Assert.AreEqual(1, _context.Resolutions.Count()); Assert.AreEqual(1, _context.ResolutionMoveAmendments.Count()); Assert.AreEqual(1, _context.OperativeParagraphs.Count()); _context.OperativeParagraphs.Remove(operativeParaph); _context.SaveChanges(); Assert.AreEqual(1, _context.Resolutions.Count()); Assert.AreEqual(0, _context.ResolutionMoveAmendments.Count()); Assert.AreEqual(0, _context.ResolutionDeleteAmendments.Count()); }
public void TestRemoveOperativeParagraphRemovesChangeAmendment() { var resolution = new ResaElement(); var operativeParagraph = new ResaOperativeParagraph(); resolution.OperativeParagraphs.Add(operativeParagraph); var changeAmendment = new ResaChangeAmendment(); operativeParagraph.ChangeAmendments.Add(changeAmendment); _context.Resolutions.Add(resolution); _context.SaveChanges(); Assert.AreEqual(1, _context.Resolutions.Count()); Assert.AreEqual(1, _context.OperativeParagraphs.Count()); Assert.AreEqual(1, _context.ResolutionChangeAmendments.Count()); _context.OperativeParagraphs.Remove(operativeParagraph); _context.SaveChanges(); Assert.AreEqual(1, _context.Resolutions.Count()); Assert.AreEqual(0, _context.OperativeParagraphs.Count()); Assert.AreEqual(0, _context.ResolutionChangeAmendments.Count()); }
public IList <ResaOperativeParagraph> GetOperativeParagraphs(ResaElement resolution, ResaOperativeParagraph parent = null) { var paragraphs = _context.OperativeParagraphs .Where(n => n.Resolution == resolution && n.Parent == parent) .Include(n => n.ChangeAmendments) .Include(n => n.MoveAmendments) .OrderBy(n => n.OrderIndex) .ToList(); foreach (var paragraph in paragraphs) { paragraph.Resolution = resolution; paragraph.DeleteAmendments = GetDeleteAmendments(paragraph); } return(paragraphs); }
public int UpdateOperativeParagraph(ResaOperativeParagraph paragraph) { _context.Update(paragraph); return(_context.SaveChanges()); }