private void StoreAddress(AddressRecord addressToStore, ContentItem contact)
        {
            addressToStore.NwazetContactPartRecord_Id = contact.Id;
            bool AddNewAddress = true;

            foreach (var existingAddressRecord in contact.As <NwazetContactPart>().NwazetAddressRecord)
            {
                if (addressToStore.Id == existingAddressRecord.Id ||
                    addressToStore.Equals(existingAddressRecord))
                {
                    AddNewAddress = false;
                    existingAddressRecord.TimeStampUTC = DateTime.UtcNow;
                    // little trick to cause nHibernate to "replace" the old address
                    // with the updated one:
                    addressToStore.Id = existingAddressRecord.Id;
                    _addressRecord.Update(addressToStore);
                    _addressRecord.Flush();
                }
            }
            if (AddNewAddress)
            {
                _addressRecord.Create(addressToStore);
                _addressRecord.Flush();
            }
        }
        private void StoreAddress(Address address, string typeAddress, ContentItem contact)
        {
            var typeAddressValue = (AddressRecordType)Enum.Parse(typeof(AddressRecordType), typeAddress);

            Mapper.Initialize(cfg => {
                cfg.CreateMap <Address, AddressRecord>();
            });
            var addressToStore = new AddressRecord();

            Mapper.Map <Address, AddressRecord>(address, addressToStore);
            addressToStore.AddressType = typeAddressValue;
            addressToStore.NwazetContactPartRecord_Id = contact.Id;
            bool AddNewAddress = true;

            foreach (var existingAddressRecord in contact.As <NwazetContactPart>().NwazetAddressRecord)
            {
                if (addressToStore.Equals(existingAddressRecord))
                {
                    AddNewAddress = false;
                    existingAddressRecord.TimeStampUTC = DateTime.UtcNow;
                    _addressRecord.Update(existingAddressRecord);
                    _addressRecord.Flush();
                }
            }
            if (AddNewAddress)
            {
                _addressRecord.Create(addressToStore);
                _addressRecord.Flush();
            }
        }
Beispiel #3
0
        public void TestA(string name, string ip)
        {
            IPAddress     original = IPAddress.Parse(ip);
            AddressRecord record   = new AddressRecord(name, original.ToIPV4());

            Assert.True(record.IPAddress.Equals(original));

            AddressRecord parsedRecord = this.Roundtrip <AddressRecord>(record);

            Assert.True(parsedRecord.Equals(record));
        }