/// <summary> /// Binds the data. /// </summary> private void BindData() { // No support for saving addresses for anonymous user if (Profile.IsAnonymous) { rbShipToNewAddress.Checked = true; trShippingAddresses.Visible = false; return; } CustomerAddressCollection addresses = null; if (Profile.Account != null) { addresses = Profile.Account.Addresses; } if (addresses != null && addresses.Count > 0) { AddressList.DataSource = addresses; AddressList.DataBind(); } else { trShippingAddresses.Visible = false; } rbShipToNewAddress.Checked = true; }
private void OnDeleteAddress() { if (this.Entity.CustomerAddresseCollection != null && this.Entity.CustomerAddresseCollection.Any(x => x.IsSelected)) { var qureyItems = this.Entity.CustomerAddresseCollection.Where(x => x.IsSelected && (x.ID.HasValue && x.ID.Value > 0) && x.IsDeleted == false).ToList(); if (qureyItems.Any()) { CustomerAction.DeleteCustomerAddresses(this.DBConnectionString, qureyItems); qureyItems.ForEach(x => x.IsDeleted = true); } var items = this.Entity.CustomerAddresseCollection.Where(x => x.IsSelected && (!x.ID.HasValue || x.ID.Value <= 0)).ToList(); if (items.Any()) { foreach (var customerAddress in items) { this.Entity.CustomerAddresseCollection.Remove(customerAddress); } var tempCollection = new CustomerAddressCollection(this.Entity.CustomerAddresseCollection.ToList()); this.Entity.CustomerAddresseCollection = null; this.Entity.CustomerAddresseCollection = tempCollection.InternalList; this.Entity.NotifyPropertyChanged("CustomerAddresseCollection"); } } }
/// <summary> /// Indexes the catalog entry dto. /// </summary> /// <param name="indexer">The indexer.</param> /// <param name="account">The account.</param> /// <returns></returns> private int IndexAccount(IndexBuilder indexer, Account account) { int indexCounter = 0; Document doc = new Document(); // Add constant fields doc.Add(new Field("_id", account.PrincipalId.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED)); doc.Add(new Field("_providerkey", account.ProviderKey, Field.Store.YES, Field.Index.UN_TOKENIZED)); doc.Add(new Field("_type", account.Type, Field.Store.YES, Field.Index.UN_TOKENIZED)); doc.Add(new Field("_metaclass", account.MetaClass.Name, Field.Store.YES, Field.Index.UN_TOKENIZED)); foreach (MetaField field in account.MetaClass.MetaFields) { AddField(doc, field, account.GetValues()); } CustomerAddressCollection addresses = account.Addresses; if (addresses != null) { foreach (CustomerAddress address in addresses) { foreach (MetaField field in address.MetaClass.MetaFields) { AddField(doc, field, account.GetValues()); } } } indexer.AddDocument(doc); indexCounter++; return(indexCounter); }
private void OnAddAddress() { if (this.Entity.CustomerAddresseCollection == null) { this.Entity.CustomerAddresseCollection = new Collection <CustomerAddress>(); } var tempCollection = new CustomerAddressCollection(this.Entity.CustomerAddresseCollection.ToList()); tempCollection.InternalList.Add(new CustomerAddress()); this.Entity.CustomerAddresseCollection = null; this.Entity.CustomerAddresseCollection = tempCollection.InternalList; this.Entity.NotifyPropertyChanged("CustomerAddresseCollection"); }
/// <summary> /// Checks if customer address collection already contains the specified address. /// </summary> /// <param name="collection">Customer addresses collection (Profile.Account.Addresses).</param> /// <param name="address">Address to check.</param> /// <returns>True, if address is already in the collection.</returns> /// <remarks>Only address' properties are checked (like first, last name, city, state,...). Address name and addressId are ignored. /// </remarks> public static bool IsAddressInCollection(CustomerAddressCollection collection, CustomerAddress address) { if (address == null) { return(false); } bool found = false; foreach (CustomerAddress tmpAddress in collection) { if (CheckAddressesEquality(tmpAddress, address)) { found = true; break; } } return(found); }
/// <summary> /// Merges CustomerAddresses for a Customer. /// </summary> /// <param name="customerId"></param> /// <param name="caCol"></param> public void MergeAddresses(int customerId, CustomerAddressCollection caCol) { ThrowIfNull(caCol); caCol.CustomerAddresses = caCol.CustomerAddresses ?? new List <CustomerAddress>(); ValidateAndThrow(caCol, new CustomerAddressCollectionValidator()); // removes var caColCustomerAddresses = caCol.CustomerAddresses as CustomerAddress[] ?? caCol.CustomerAddresses.ToArray(); var idsToKeep = caColCustomerAddresses.Select(ca => ca.Address.Id).ToArray(); var caToRemove = Context.CustomerAddresses.Where(c => c.CustomerId == customerId && !idsToKeep.Contains(c.AddressId)).ToArray(); var adToRemove = caToRemove.Select(ca => Spoof <Model.Address>(ca.AddressId)).ToList(); adToRemove.ForEach(a => Context.Addresses.Attach(a)); Context.CustomerAddresses.RemoveRange(caToRemove); Context.Addresses.RemoveRange(adToRemove); // add and update foreach (var cAddr in caColCustomerAddresses) { if (cAddr.Address.Id == 0) { cAddr.CustomerId = customerId; // just in case Context.Addresses.Add(cAddr.Address); Context.CustomerAddresses.Add(cAddr); } else { cAddr.CustomerId = customerId; // just in case cAddr.AddressId = cAddr.Address.Id; Context.Addresses.Attach(cAddr.Address); Context.SetEntityState(cAddr.Address, EntityState.Modified); Context.CustomerAddresses.Attach(cAddr); Context.SetEntityState(cAddr, EntityState.Modified); } } Context.SaveChanges(); }