public void ApplyParticipants(Guid[] newParticipantIds) { var delta = CollectionDeltaCalculator.CalculateCollectionDelta(newParticipantIds, Participants, s => s, d => d.ParticipantId); delta.Added.ForEach(a => Participants.Add(new CourseParticipant { ParticipantId = a, CourseId = Id })); delta.Removed.ForEach(r => Participants.Remove(r)); }
public virtual void MapCollection(IEnumerable <TSource> source, ICollection <TDestination> destination) { Guid SourceProperty(TSource x) => x.Id; Guid DestinationProperty(TDestination x) => x.Id; var delta = CollectionDeltaCalculator.CalculateCollectionDelta(source, destination, SourceProperty, DestinationProperty); delta.Added.ForEach(x => destination.Add(_mapper.Map(x, _repository.Create()))); delta.Updated.ForEach(x => _mapper.Map(x.SourceItem, x.DestinationItem)); delta.Removed.ForEach(_repository.Remove); }