/// <summary>
        /// Saves the addresses.
        /// </summary>
        private void SaveAddresses()
        {
            ContactServiceClient contactService = null;
            ClientServiceClient clientService = null;
            try
            {
                CheckForModifiedAddress();
                List<string> updatedAddresses = (List<string>)ViewState[UpdatedAddresses];
                //Check if any of the addresses have been modified
                if (updatedAddresses.Count > 0)
                {
                    contactService = new ContactServiceClient();
                    List<Address> clientAddresses = (List<Address>)Session[SessionName.ClientAddresses];
                    foreach (string addressType in updatedAddresses)
                    {
                        foreach (Address address in clientAddresses)
                        {
                            if (address.TypeId.ToString() == addressType)
                            {

                                if (_logonSettings.UserType == (int)DataConstants.UserType.ThirdParty && Request.QueryString["mydetails"] == "true")
                                {
                                    address.MemberId = _logonSettings.MemberId;
                                    address.OrganisationId = _logonSettings.OrganisationId;
                                }
                                else
                                {
                                    address.MemberId = (Guid)Session[SessionName.MemberId];
                                    address.OrganisationId = (Guid)Session[SessionName.OrganisationId];
                                }

                                AddressReturnValue returnValue = contactService.SaveAddress(_logonSettings.LogonId, address);
                                if (!returnValue.Success)
                                {
                                    _lblMessage.CssClass = "errorMessage";
                                    _lblMessage.Text = returnValue.Message;
                                }
                                break;
                            }
                        }
                    }
                    updatedAddresses.Clear();
                    //Reload the addresses
                    clientService = new ClientServiceClient();
                    AddressSearchCriteria searchCriteria = new AddressSearchCriteria();
                    searchCriteria.MemberId = _memberId;
                    searchCriteria.OrganisationId = _organisationId;
                    CollectionRequest collectionRequest = new CollectionRequest();
                    collectionRequest.ForceRefresh = true;

                    if (Request.QueryString["mydetails"] == "true" && _logonSettings.UserType == (int)DataConstants.UserType.ThirdParty)
                    {
                        AddressSearchReturnValue addressSearchReturnValue = new AddressSearchReturnValue();
                        ContactServiceClient serviceClient = new ContactServiceClient();
                        addressSearchReturnValue = serviceClient.GetContactAddresses(_logonSettings.LogonId, collectionRequest, searchCriteria);
                        clientAddresses.Clear();
                        //Store the addresses in a list so that we can add items if necessary
                        foreach (Address address in addressSearchReturnValue.Addresses.Rows)
                        {
                            clientAddresses.Add(address);
                        }

                    }
                    else
                    {
                        AddressSearchReturnValue addresses = clientService.GetClientAddresses(_logonSettings.LogonId,
                                                                                            collectionRequest,
                                                                                            searchCriteria);
                        clientAddresses.Clear();
                        //Store the addresses in a list so that we can add items if necessary
                        foreach (Address address in addresses.Addresses.Rows)
                        {
                            clientAddresses.Add(address);
                        }
                    }

                    if (Request.QueryString["mydetails"] == "true" && _logonSettings.UserType == (int)DataConstants.UserType.ThirdParty)
                    {
                        DisplayContactAddressDetails();
                    }
                    else
                    {
                        DisplayAddressDetails();
                    }
                }
            }
            catch (System.ServiceModel.EndpointNotFoundException)
            {
                _lblMessage.Text = DataConstants.WSEndPointErrorMessage;
                _lblMessage.CssClass = "errorMessage";
            }
            catch (Exception ex)
            {
                _lblMessage.CssClass = "errorMessage";
                _lblMessage.Text = ex.Message;
            }
            finally
            {
                if (contactService != null)
                {
                    if (contactService.State != System.ServiceModel.CommunicationState.Faulted)
                        contactService.Close();
                }

                if (clientService != null)
                {
                    if (clientService.State != System.ServiceModel.CommunicationState.Faulted)
                        clientService.Close();
                }
            }
        }