public async Task AddAddress(Address address) { AddressRestService addressRestService = new AddressRestService(); created_address = await addressRestService.SaveAddressAsync(address, true); Customer_Address customer_Address = new Customer_Address(); customer_Address.CustomerID = created_account.Customer.CustomerID; customer_Address.AddressID = created_address.AddressID; customer_Address.AddressLabel = "Default"; Customer_AddressRestService customer_AddressRestService = new Customer_AddressRestService(); await customer_AddressRestService.SaveCustomer_AddressAsync(customer_Address, true); }
//add an aditional address to customer account async void AddAddressClicked() { CustomerAddressValidator customer_address_validator = new CustomerAddressValidator(); ValidationResult results = customer_address_validator.Validate(address); //validate address if (!results.IsValid) //invalid - show error { String result_messages = results.ToString("\n"); await Application.Current.MainPage.DisplayAlert("Error", result_messages, "OK"); } else //valid try to save address { AddressRestService addressRestService = new AddressRestService(); Customer_AddressRestService customer_AddressRestService = new Customer_AddressRestService(); Address created_address = await addressRestService.SaveAddressAsync(address, true); //save address entry to db Customer_Address customer_Address = new Customer_Address(); //gather customer_address data customer_Address.CustomerID = (int)Application.Current.Properties["customerID"]; customer_Address.AddressID = created_address.AddressID; customer_Address.AddressLabel = customer_address.AddressLabel; try //to save customer_address entry to db { await customer_AddressRestService.SaveCustomer_AddressAsync(customer_Address, true); await Application.Current.MainPage.DisplayAlert("Success", "Address Saved", "OK"); await Application.Current.MainPage.Navigation.PushAsync(new AccountManagementPage()); } catch (Exception e) { await Application.Current.MainPage.DisplayAlert("Error", e.Message, "OK"); } } }