private static void SaveProjections(IPersistenceProvider transaction, IEnumerable <ProjectionItem <IPersistable> > changes) { foreach (var item in changes) { switch (item.ProjectionItemAction) { case ProjectionItemActionEnum.Nothing: break; case ProjectionItemActionEnum.New: var result = transaction.Insert(item.Value); if (result != PersistenceResultEnum.Success) { throw new ConcurrencyException("The item with id {0} is already inserted".InvariantFormat(item.Value.DocumentKey)); } break; case ProjectionItemActionEnum.UpdateOrNew: result = transaction.UpdateOrInsert(item.Value); if (result != PersistenceResultEnum.Success) { throw new ConcurrencyException("The item with id {0} has been updated before this update".InvariantFormat(item.Value.DocumentKey)); } break; case ProjectionItemActionEnum.Delete: result = transaction.Delete(item.Value); if (result != PersistenceResultEnum.Success) { throw new ConcurrencyException("The item with id {0} cannot be deleted.".InvariantFormat(item.Value.DocumentKey)); } break; default: throw new EventSourcingException("The type of the item is invalid"); } } }