public bool Save(Customer customer) { var result = true; if (customer.HasChanges) { if (customer.IsValid) { if (customer.IsNew) { result = _storage.AddRecord( new KeyValuePair <string, string>("Guid", customer.Guid.ToString()), new KeyValuePair <string, string>("FirstName", customer.FirstName), new KeyValuePair <string, string>("LastName", customer.LastName), new KeyValuePair <string, string>("Email", customer.Email), new KeyValuePair <string, string>("Type", ((int)customer.Type).ToString())); } else { result = _storage.UpdateRecord(customer.Guid.ToString(), new KeyValuePair <string, string>("FirstName", customer.FirstName), new KeyValuePair <string, string>("LastName", customer.LastName), new KeyValuePair <string, string>("Email", customer.Email), new KeyValuePair <string, string>("Type", ((int)customer.Type).ToString())); _customerToAddressStorage.RemoveAllMatchingRecords("CustomerGuid", customer.Guid.ToString()); } foreach (var address in customer.Addresses) { _customerToAddressStorage.AddRecord( new KeyValuePair <string, string>("CustomerGuid", customer.Guid.ToString()), new KeyValuePair <string, string>("AddressGuid", address.Guid.ToString())); } } else { result = false; } } else { result = false; } return(result); }