Пример #1
0
        private void When(TerrainObjectHouseNumberWasImportedFromCrab @event)
        {
            var crabTerrainObjectHouseNumberId = new CrabTerrainObjectHouseNumberId(@event.TerrainObjectHouseNumberId);

            var crabHouseNumberId = new CrabHouseNumberId(@event.HouseNumberId);

            if (@event.Modification == CrabModification.Delete)
            {
                _activeHouseNumberIdsByTerreinObjectHouseNr.Remove(crabTerrainObjectHouseNumberId);
            }
            else
            {
                _activeHouseNumberIdsByTerreinObjectHouseNr[crabTerrainObjectHouseNumberId] = crabHouseNumberId;
            }

            WhenCrabEventApplied();
        }
        public void ImportTerrainObjectHouseNumberFromCrab(
            CrabTerrainObjectHouseNumberId terrainObjectHouseNumberId,
            CrabTerrainObjectId terrainObjectId,
            CrabHouseNumberId houseNumberId,
            CrabLifetime lifetime,
            CrabTimestamp timestamp,
            CrabOperator @operator,
            CrabModification?modification,
            CrabOrganisation?organisation)
        {
            GuardRemoved(modification);

            var legacyEvent = new TerrainObjectHouseNumberWasImportedFromCrab(
                terrainObjectHouseNumberId,
                terrainObjectId,
                houseNumberId,
                lifetime,
                timestamp,
                @operator,
                modification,
                organisation);

            var addressId = AddressId.CreateFor(houseNumberId);

            if (_addressCollection.Contains(addressId) &&
                (modification == CrabModification.Delete || lifetime.EndDateTime.HasValue))
            {
                if (_activeHouseNumberIdsByTerreinObjectHouseNr.Values.Count(x => x == houseNumberId) == 1)
                {
                    foreach (var addressIdToRemove in _addressCollection.AddressIdsEligableToRemoveFor(houseNumberId))
                    {
                        ApplyChange(new ParcelAddressWasDetached(_parcelId, addressIdToRemove));
                    }

                    ApplyChange(new ParcelAddressWasDetached(_parcelId, addressId));
                }
            }
            else
            {
                if (_activeHouseNumberIdsByTerreinObjectHouseNr.ContainsKey(terrainObjectHouseNumberId) &&
                    _activeHouseNumberIdsByTerreinObjectHouseNr[terrainObjectHouseNumberId] != houseNumberId)
                {
                    var currentCrabHouseNumberId = _activeHouseNumberIdsByTerreinObjectHouseNr[terrainObjectHouseNumberId];
                    if (_activeHouseNumberIdsByTerreinObjectHouseNr.Values.Count(x => x == currentCrabHouseNumberId) == 1)
                    {
                        foreach (var addressIdToRemove in _addressCollection.AddressIdsEligableToRemoveFor(
                                     currentCrabHouseNumberId))
                        {
                            ApplyChange(new ParcelAddressWasDetached(_parcelId, addressIdToRemove));
                        }

                        ApplyChange(new ParcelAddressWasDetached(_parcelId,
                                                                 AddressId.CreateFor(currentCrabHouseNumberId)));
                    }
                }

                if (!_addressCollection.Contains(addressId) &&
                    modification != CrabModification.Delete &&
                    !lifetime.EndDateTime.HasValue)
                {
                    ApplyChange(new ParcelAddressWasAttached(_parcelId, addressId));

                    foreach (var addressIdToAdd in _addressCollection.AddressIdsEligableToAddFor(houseNumberId))
                    {
                        ApplyChange(new ParcelAddressWasAttached(_parcelId, addressIdToAdd));
                    }
                }
            }

            ApplyChange(legacyEvent);
        }