public AddressDialogViewModel(Address item, object[] countries)
		{

			InnerItem = item;
			_innerItem.PropertyChanged += _innerItem_PropertyChanged;
			AllCountries = countries;

			OnPropertyChanged("AddressType");
		}
Ejemplo n.º 2
0
        private bool RaiseEditAddressRequest(Address item, string title)
        {
            var result = false;
			var itemVM = _addressVmFactory.GetViewModelInstance(new KeyValuePair<string, object>("item", item), new KeyValuePair<string, object>("countries", _allCountries));
            DisableableCommandConfirmRequest.Raise(
                new ConditionalConfirmation(itemVM.Validate)
                {
                    Title = title,
                    Content = itemVM
                },
                (x) =>
                {
                    result = x.Confirmed;
                });

            return result;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// raised on address edit click
 /// </summary>
 private void RaiseEditAddressRequest(Address originalItem)
 {
     var item = originalItem.DeepClone(_entityFactory as IKnownSerializationTypes);
     if (RaiseEditAddressRequest(item, "Edit Address"))
     {
         OnUIThread(()=>originalItem.InjectFrom<CloneInjection>(item));
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// raised on add address click
 /// </summary>
 private void RaiseAddAddressRequest()
 {
     var item = new Address() { Type = "Primary" };
     if (RaiseEditAddressRequest(item, "Add Address"))
     {
         OnUIThread(() => InnerItem.Addresses.Add(item));
     }
 }
		private void EditAddress(Address item)
		{
			if (AddAddressPhoneEmailInteractioNRequest != null)
			{
				var addressToEdit = item.DeepClone(_entityFactory as IKnownSerializationTypes);
				var countries = CountryRepository.Countries.Expand(c => c.Regions).ToArray();

				var parameters = new List<KeyValuePair<string, object>>
					{
						new KeyValuePair<string, object>("item", addressToEdit),
						new KeyValuePair<string, object>("countries", countries)
					};

				var itemVm = _addressVmFactory.GetViewModelInstance(parameters.ToArray());

				var confirmation = new ConditionalConfirmation { Title = "Enter address details", Content = itemVm };

				AddAddressPhoneEmailInteractioNRequest.Raise(confirmation,
					(x) =>
					{
						if (x.Confirmed)
						{
							var itemToUpdate =
								(x.Content as IAddressDialogViewModel).InnerItem;

							var itemFromInnerItem =
								ContactAddresses.SingleOrDefault(
									a => a.AddressId == itemToUpdate.AddressId);

							if (itemFromInnerItem != null)
							{
								itemFromInnerItem.InjectFrom(itemToUpdate);
								_parentViewModel.IsModified = true;
							}

						}
					});
			}
		}
		private void MakeBillingAddress(Address item)
		{
			foreach (var addressItem in ContactAddresses.Where(addressItem => addressItem.Type == AddressType.Billing.ToString()))
			{
				addressItem.Type = null;
			}

			item.Type = AddressType.Billing.ToString();
			_parentViewModel.IsModified = true;
		}
		private void RemoveAddress(Address item)
		{
			if (ContactAddresses != null)
			{
				ContactAddresses.Remove(item);
			}
		}
		public void AddEditAndRemoveAddressFromContactTest()
		{
			var client = GetRepository();

			Contact contactFromDb = client.Members.OfType<Contact>().
				Expand(c => c.Addresses).FirstOrDefault();

			client.Attach(contactFromDb);

			Assert.IsNotNull(contactFromDb);


			Address address1 = new Address();
			address1.City = "testCity1";
			address1.CountryCode = "testCountryCode1";
			address1.CountryName = "testCountryName1";
			address1.Line1 = "testLine1_1";
			address1.Line2 = "testLine2_1";
			address1.PostalCode = "testPostalCode1";
			address1.RegionName = "testResgion1";
			address1.StateProvince = "testState1";
			address1.Type = "Primary";

			Address address2 = new Address();
			address2.City = "testCity2";
			address2.CountryCode = "testCountryCode2";
			address2.CountryName = "testCountryName2";
			address2.Line1 = "testLine1_2";
			address2.Line2 = "testLine2_2";
			address2.PostalCode = "testPostalCode2";
			address2.RegionName = "testResgion2";
			address2.StateProvince = "testState2";
			address2.Type = "Primary";

			//add 2 addresses to contact
			contactFromDb.Addresses.Add(address1);
			contactFromDb.Addresses.Add(address2);

			Assert.IsTrue(contactFromDb.Addresses.Count != 0);

			//save contact
			client.UnitOfWork.Commit();


			client = GetRepository();

			Contact contactForCheck = client.Members.Where(m => m.MemberId == contactFromDb.MemberId).OfType<Contact>().
				Expand(c => c.Addresses).SingleOrDefault();

			client.Attach(contactForCheck);

			Assert.IsNotNull(contactForCheck);
			Assert.IsNotNull(contactForCheck.Addresses);
			Assert.IsTrue(contactForCheck.Addresses.Count >= 2);

			//edit address 1
			Address address1ForCheck = contactForCheck.Addresses.Where(a => a.AddressId == address1.AddressId).SingleOrDefault();
			address1ForCheck.Line1 = "updated line 1_1";
			address1ForCheck.Line2 = "updated line 2_1";
			//edit address 2
			Address address2ForCheck = contactForCheck.Addresses.Where(a => a.AddressId == address2.AddressId).SingleOrDefault();
			address2ForCheck.Line1 = "updated line 1_2";
			address2ForCheck.Line2 = "updated line 2_2";

			client.UnitOfWork.Commit();


			client = GetRepository();

			Contact contactForDelete = client.Members.Where(m => m.MemberId == contactFromDb.MemberId).OfType<Contact>().
				Expand(c => c.Addresses).SingleOrDefault();

			client.Attach(contactForDelete);

			Assert.IsNotNull(contactForDelete);
			Assert.IsNotNull(contactForDelete.Addresses);
			Assert.IsTrue(contactForDelete.Addresses.Count >= 2);

			Address updatedAddress1 = contactForDelete.Addresses.Where(a => a.AddressId == address1ForCheck.AddressId).SingleOrDefault();

			Assert.IsNotNull(updatedAddress1);
			Assert.IsTrue(updatedAddress1.Line1 == "updated line 1_1");
			Assert.IsTrue(updatedAddress1.Line2 == "updated line 2_1");

			Address updatedAddress2 = contactForDelete.Addresses.Where(a => a.AddressId == address2ForCheck.AddressId).SingleOrDefault();

			Assert.IsNotNull(updatedAddress2);
			Assert.IsTrue(updatedAddress2.Line1 == "updated line 1_2");
			Assert.IsTrue(updatedAddress2.Line2 == "updated line 2_2");


			contactForDelete.Addresses.Clear();
			client.Remove(updatedAddress1);
			client.Remove(updatedAddress2);

			client.UnitOfWork.Commit();


			client = GetRepository();

			Contact contactWithRemovedAddresses = client.Members.Where(m => m.MemberId == contactFromDb.MemberId).OfType<Contact>().
				Expand(c => c.Addresses).SingleOrDefault();

			Assert.IsNotNull(contactWithRemovedAddresses);
			Assert.IsNotNull(contactWithRemovedAddresses.Addresses);
			Assert.IsTrue(contactWithRemovedAddresses.Addresses.Count == 1);

		}
		private Address CreateAddress(string line1, string line2, string city, string countryCode, string countryName, string region, string postalCode, string type)
		{
			Address retVal = new Address
			{
				Line1 = line1,
				Line2 = line2,
				City = city,
				CountryCode = countryCode,
				CountryName = countryName,
				RegionName = region,
				PostalCode = postalCode,
				Type = type
			};

			return retVal;
		}
Ejemplo n.º 10
0
 /// <summary>
 /// Converts to customer address.
 /// </summary>
 /// <param name="address">The address.</param>
 /// <returns>Address.</returns>
 private static Address ConvertToCustomerAddress(AddressModel address)
 {
     var addr = new Address();
     addr.InjectFrom(address);
     return addr;
 }
        private Address CreateAddress(string line1, string name, string city, string countryCode, string countryName,
                                      string postalCode)
        {
            var retVal = new Address
                {
                    Line1 = line1,
                    Name = name,
                    City = city,
                    CountryCode = countryCode,
                    CountryName = countryName,
                    PostalCode = postalCode,
                };

            return retVal;
        }
        public void Can_edit_Address_in_Contact()
        {
            var client = GetRepository();

			var contactWithNewAddress = new Contact();
			contactWithNewAddress.FullName = "test";


            var address1 = new Address();
	        address1.Name = "testName1";
            address1.City = "testCity1";
            address1.CountryCode = "testCountryCode1";
            address1.CountryName = "testCountryName1";
            address1.Line1 = "testLine1_1";
            address1.Line2 = "testLine2_1";
            address1.PostalCode = "testPostalCode1";
            address1.RegionName = "testResgion1";
            address1.StateProvince = "testState1";
            address1.Type = "Primary";

            var address2 = new Address();
			address2.Name = "testName2";
            address2.City = "testCity2";
            address2.CountryCode = "testCountryCode2";
            address2.CountryName = "testCountryName2";
            address2.Line1 = "testLine1_2";
            address2.Line2 = "testLine2_2";
            address2.PostalCode = "testPostalCode2";
            address2.RegionName = "testResgion2";
            address2.StateProvince = "testState2";
            address2.Type = "Primary";

            //add 2 addresses to contact
			contactWithNewAddress.Addresses.Add(address1);
			contactWithNewAddress.Addresses.Add(address2);

			Assert.True(contactWithNewAddress.Addresses.Count != 0);

            //save contact
			client.Add(contactWithNewAddress);
            client.UnitOfWork.Commit();


            client = GetRepository();

			var contactForCheck = client.Members.Where(m => m.MemberId == contactWithNewAddress.MemberId).OfType<Contact>().
                                         Expand(c => c.Addresses).SingleOrDefault();

            client.Attach(contactForCheck);

            Assert.NotNull(contactForCheck);
            Assert.NotNull(contactForCheck.Addresses);
            Assert.True(contactForCheck.Addresses.Count == 2);

            //edit address 1
            var address1ForCheck =
                contactForCheck.Addresses.Where(a => a.AddressId == address1.AddressId).SingleOrDefault();
            address1ForCheck.Line1 = "updated line 1_1";
            address1ForCheck.Line2 = "updated line 2_1";
            //edit address 2
            var address2ForCheck =
                contactForCheck.Addresses.Where(a => a.AddressId == address2.AddressId).SingleOrDefault();
            address2ForCheck.Line1 = "updated line 1_2";
            address2ForCheck.Line2 = "updated line 2_2";

			
            client.UnitOfWork.Commit();


            client = GetRepository();

            var contactForDelete =
				client.Members.Where(m => m.MemberId == contactWithNewAddress.MemberId).OfType<Contact>().
                       Expand(c => c.Addresses).SingleOrDefault();

            client.Attach(contactForDelete);

            Assert.NotNull(contactForDelete);
            Assert.NotNull(contactForDelete.Addresses);
            Assert.True(contactForDelete.Addresses.Count >= 2);

            var updatedAddress1 =
                contactForDelete.Addresses.Where(a => a.AddressId == address1ForCheck.AddressId).SingleOrDefault();

            Assert.NotNull(updatedAddress1);
            Assert.True(updatedAddress1.Line1 == "updated line 1_1");
            Assert.True(updatedAddress1.Line2 == "updated line 2_1");

            var updatedAddress2 =
                contactForDelete.Addresses.Where(a => a.AddressId == address2ForCheck.AddressId).SingleOrDefault();

            Assert.NotNull(updatedAddress2);
            Assert.True(updatedAddress2.Line1 == "updated line 1_2");
            Assert.True(updatedAddress2.Line2 == "updated line 2_2");


            contactForDelete.Addresses.Clear();
            client.Remove(updatedAddress1);
            client.Remove(updatedAddress2);

            client.UnitOfWork.Commit();


            client = GetRepository();

            var contactWithRemovedAddresses =
				client.Members.Where(m => m.MemberId == contactWithNewAddress.MemberId).OfType<Contact>().
                       Expand(c => c.Addresses).SingleOrDefault();

            Assert.NotNull(contactWithRemovedAddresses);
            Assert.NotNull(contactWithRemovedAddresses.Addresses);
            Assert.True(contactWithRemovedAddresses.Addresses.Count == 0);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Address view.
 /// </summary>
 /// <param name="address">The address.</param>
 /// <returns>ActionResult.</returns>
 public ActionResult AddressView(Address address)
 {
     return View(address);
 }
Ejemplo n.º 14
0
        public ActionResult AddressEdit(AddressEditModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.Address != null)
                {
                    var u = _userClient.GetCurrentCustomer(false);
                    Organization org = null;

                    if (!String.IsNullOrEmpty(model.OrganizationId))
                    {
                        org = _userClient.GetOrganizationById(model.OrganizationId);
                    }

                    var parent = org == null ? u : (Member)org;

                    if (model.IsDefaultBilling)
                    {
                        //remove previous default Billing
                        var address =
                            parent.Addresses.FirstOrDefault(x => x.Name.Contains(UserHelper.DefaultBilling));
                        if (address != null)
                        {
                            address.Name = address.Name.Replace(UserHelper.DefaultBilling, string.Empty);
                        }

                        model.Address.Name += UserHelper.DefaultBilling;
                    }

                    if (model.IsDefaultShipping)
                    {
                        //remove previous default Shipping
                        var address =
                            parent.Addresses.FirstOrDefault(x => x.Name.Contains(UserHelper.DefaultShipping));
                        if (address != null)
                        {
                            address.Name = address.Name.Replace(UserHelper.DefaultShipping, string.Empty);
                        }

                        model.Address.Name += UserHelper.DefaultShipping;
                    }

                    var exisintgAddress = parent.Addresses.FirstOrDefault(p => p.AddressId.Equals(model.Address.AddressId));

                    if (exisintgAddress != null)
                    {
                        exisintgAddress.InjectFrom(model.Address);
                    }
                    else
                    {
                        //create new
                        var newAddress = new Address();
                        newAddress.InjectFrom(model.Address);

                        if (parent.Addresses.Count == 0)
                        {
                            newAddress.Name += String.Format("{0}{1}", UserHelper.DefaultBilling,
                                                                UserHelper.DefaultShipping);
                        }

                        parent.Addresses.Add(newAddress);
                    }

                    _userClient.SaveCustomerChanges(u.MemberId);
                }

                return RedirectToAction(String.IsNullOrEmpty(model.OrganizationId) ? "AddressBook" : "CompanyAddressBook");
            }

            model.Countries = _countryClient.GetAllCountries();
            return View(model);
        }
Ejemplo n.º 15
0
		public static OrderAddress ConvertToOrderAddress(Address address)
		{
			var addr = new OrderAddress();
			addr.InjectFrom(address);
			return addr;
		}
Ejemplo n.º 16
0
		public static Address ConvertToCustomerAddress(OrderAddress address)
		{
			var addr = new Address();
			addr.InjectFrom(address);
			return addr;
		}