protected override void InMemoryLogic(EntityCollectionBase target) { DateTime minStartDate = Moment; DateTime maxEndDate = EndDate; target.ForEach(delegate(int index, CollectionItem item) { if (item.Item.Equals(target.ForeignItem(this))) { if (item.Overlaps(Moment)) { if (minStartDate > item.StartDate) { minStartDate = item.StartDate ?? DateTime.MinValue; } if (maxEndDate < item.EndDate) { maxEndDate = item.EndDate ?? DateTime.MaxValue; } target.RemoveAt(index); } } }); target.Add(target.NewCollectionItem(target.Parent, target.ForeignItem(this), minStartDate, maxEndDate)); }
protected override void InMemoryLogic(EntityCollectionBase target) { bool contains = false; target.ForEach(delegate(int index, CollectionItem item) { if (item.Item.Equals(target.ForeignItem(this))) { contains = true; } }); if (!contains) { target.Add(target.NewCollectionItem(target.Parent, target.ForeignItem(this), null, null)); } }
protected override void InMemoryLogic(EntityCollectionBase target) { bool wasAdded = false; target.ForEach(delegate(int index, CollectionItem item) { if (item.Item.Equals(target.ForeignItem(this))) { if (item.IsAfter(Moment)) { target.RemoveAt(index); } else if (item.Overlaps(Moment)) { target.SetItem(index, target.NewCollectionItem(target.Parent, item.Item, item.StartDate, null)); wasAdded = true; } } }); if (!wasAdded) { target.Add(target.NewCollectionItem(target.Parent, target.ForeignItem(this), Moment, null)); } }