public bool Delete(IEnumerable <DataRepository> observedDataToBeRemoved) { var observedDataToRemoveList = observedDataToBeRemoved.ToList(); var usedInAnalyzablesCache = new Cache <DataRepository, IEnumerable <IUsesObservedData> >(); observedDataToRemoveList.Each(x => { usedInAnalyzablesCache[x] = allUsersOfObservedData(x); }); var observedDataThatCanBeRemoved = observedDataToRemoveList.Where(x => !usedInAnalyzablesCache[x].Any()).ToList(); var observedDataNotDeleted = observedDataToRemoveList.Except(observedDataThatCanBeRemoved); var observedDataNotDeletedMessage = observedDataNotDeleted.Select(x => messageForObservedDataUsedByAnalysable(x, usedInAnalyzablesCache)); //not one observed data can be deleted because all of them are used if (!observedDataThatCanBeRemoved.Any()) { throw new CannotDeleteObservedDataException(observedDataNotDeletedMessage); } var viewResult = _dialogCreator.MessageBoxYesNo(Captions.ReallyDeleteAllObservedData(observedDataNotDeletedMessage)); if (viewResult == ViewResult.No) { return(false); } return(deleteAll(observedDataThatCanBeRemoved)); }