public void UpdateCustomer()
        {
            Customer c = new Customer()
            {
                Attention = new Attention()
                {
                    CustomerContactNumber = 1,
                    Self = "https://restapi.e-conomic.com/customers/9/contacts/1"
                },
                Address         = string.Empty,
                Balance         = 1,
                CiNumber        = string.Empty,
                Barred          = false,
                Country         = "Danmark",
                County          = "Danmark",
                CreditLimit     = 1,
                CustomerContact = new CustomerContact()
                {
                    CustomerContactnumber = 1,
                    Self = "https://restapi.e-conomic.com/customers/9/contacts/1"
                },
                salesPerson = new SalesPerson()
                {
                    EmployeeNumber = 1,
                    Self           = "https://restapi.e-conomic.com/employees/1"
                },
                CustomerNumber = 9,
                Ean            = string.Empty,
                Email          = string.Empty,
                Layout         = new Layout()
                {
                    LayoutNumber = 18,
                    Name         = string.Empty,
                    Self         = "https://restapi.e-conomic.com/layouts/10"
                },
                PublicEntryNumber     = string.Empty,
                TelephoneAndFaxNumber = string.Empty,
                VatNumber             = string.Empty,
                Website       = string.Empty,
                Zip           = string.Empty,
                CustomerGroup = new CustomerGroup()
                {
                    CustomerGroupNumber = 3,
                    Name = "Websitepanel",
                    Self = "https://restapi.e-conomic.com/customer-groups/3"
                },
                Name         = "test bruger 55",
                Currency     = "DKK",
                PaymentTerms = new PaymentTerm()
                {
                    PaymentTermsNumber = 4,
                    Name = string.Empty,
                    Self = "https://restapi.e-conomic.com/payment-terms/4"
                },
                VatZone = new VatZone()
                {
                    VatZoneNumber = 1,
                    Name          = string.Empty,
                    Self          = "https://restapi.e-conomic.com/vat-zones/1"
                }
            };

            CustomerClient.UpdateCustomer(9, c);
        }
        public ActionResult UpdateProfile(CustomerUpdateViewModel profileModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var      user            = Members.GetCurrentMember();
                    int      websitePanelId  = 0;
                    int      economicId      = 0;
                    int      brainLessUserId = 0;
                    DateTime timeNow         = DateTime.Now;

                    if (user.Properties.FirstOrDefault(p => p.PropertyTypeAlias == WEBSITEPANELUSERID) != null && user.GetProperty(WEBSITEPANELUSERID).HasValue)
                    {
                        websitePanelId = (int)user.GetProperty(WEBSITEPANELUSERID).Value;
                    }

                    if (user.Properties.FirstOrDefault(p => p.PropertyTypeAlias == ECONOMICID) != null && user.GetProperty(ECONOMICID).HasValue)
                    {
                        economicId = (int)user.GetProperty(ECONOMICID).Value;
                    }

                    if (user.Properties.FirstOrDefault(p => p.PropertyTypeAlias == BRAINLESSID) != null && user.GetProperty(BRAINLESSID).HasValue)
                    {
                        brainLessUserId = (int)user.GetProperty(BRAINLESSID).Value;
                    }

                    if (Members.GetByEmail(profileModel.Email) != null)
                    {
                        throw new Exception(string.Format("Email {0} er allerede brugt. Kontakts os for nærmere information.", profileModel.Email));
                    }

                    esUsersSoapClient          client     = null;
                    esAuthenticationSoapClient clientAuth = null;

                    if (websitePanelId > 0)
                    {
                        client = new esUsersSoapClient(ESUSERSSOAP);
                        client.ClientCredentials.UserName.UserName = WEBSITEPANEL_USERNAME;
                        client.ClientCredentials.UserName.Password = WEBSITEPANEL_PASSWORD;
                        client.Open();


                        clientAuth = new esAuthenticationSoapClient(ESAUTHENTICATIONSOAP);
                        clientAuth.ClientCredentials.UserName.UserName = WEBSITEPANEL_USERNAME;
                        clientAuth.ClientCredentials.UserName.Password = WEBSITEPANEL_PASSWORD;
                        clientAuth.Open();
                    }

                    WebsitepanelService.UserInfo userInfo = null;
                    if (websitePanelId > 0)
                    {
                        userInfo = client.GetUserById(websitePanelId);
                        if (!string.IsNullOrWhiteSpace(profileModel.Address))
                        {
                            userInfo.Address = profileModel.Address;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.City))
                        {
                            userInfo.City = profileModel.City;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.FirstName))
                        {
                            userInfo.FirstName = profileModel.FirstName;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.LastName))
                        {
                            userInfo.LastName = profileModel.LastName;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.Postcode))
                        {
                            userInfo.Zip = profileModel.Postcode;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.Email))
                        {
                            userInfo.Email = profileModel.Email;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.CompanyName))
                        {
                            userInfo.CompanyName = profileModel.CompanyName;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.CVRNumber))
                        {
                            userInfo.Comments = string.Format("CVR: {0}", profileModel.CVRNumber);
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.Country))
                        {
                            var regex = new System.Text.RegularExpressions.Regex(@"([\w+\s*\.*]+\))");

                            foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
                            {
                                RegionInfo region = new RegionInfo(ci.Name);

                                var    match       = regex.Match(ci.EnglishName);
                                string countryName = match.Value.Length == 0 ? "NA" : match.Value.Substring(0, match.Value.Length - 1);

                                if (countryName == profileModel.Country)
                                {
                                    userInfo.Country = region.TwoLetterISORegionName;
                                    break;
                                }
                            }
                        }

                        userInfo.Changed = timeNow;
                    }

                    // websitepanel update
                    if (websitePanelId > 0)
                    {
                        var updateTask = client.UpdateUserAsync(userInfo);
                        if (profileModel.ConfirmPassword == profileModel.Password && !string.IsNullOrWhiteSpace(profileModel.Password))
                        {
                            if (Members.Login(user.Name, profileModel.CurrentPassword))
                            {
                                client.ChangeUserPassword(websitePanelId, profileModel.Password);
                            }
                            else
                            {
                                throw new Exception("Forkert Nuværende adgangskode. ");
                            }
                        }

                        updateTask.Wait(60000);
                    }

                    if (clientAuth != null)
                    {
                        clientAuth.Close();
                        clientAuth.Abort();
                    }

                    if (client != null)
                    {
                        client.Close();
                        client.Abort();
                    }

                    // economic get customer
                    System.Threading.Tasks.Task            eUpdateCustomerTask = null;
                    System.Threading.Tasks.Task <Customer> eGetCustomerTask    = null;
                    if (economicId > 0)
                    {
                        Customer customer = CustomerClient.GetCustomer(economicId);

                        if (!string.IsNullOrWhiteSpace(profileModel.CompanyName) || !string.IsNullOrWhiteSpace(profileModel.FirstName) || !string.IsNullOrWhiteSpace(profileModel.LastName))
                        {
                            if (!string.IsNullOrWhiteSpace(profileModel.CompanyName))
                            {
                                customer.Name = profileModel.CompanyName;
                            }
                            else
                            {
                                customer.Name = string.Format("{0} {1}", profileModel.FirstName, profileModel.LastName);
                            }
                        }

                        if (!string.IsNullOrWhiteSpace(profileModel.Address))
                        {
                            customer.Address = profileModel.Address;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.Email))
                        {
                            customer.Email = profileModel.Email;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.City))
                        {
                            customer.City = profileModel.City;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.Country))
                        {
                            customer.Country = profileModel.Country;
                            customer.County  = profileModel.Country;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.Postcode))
                        {
                            customer.Zip = profileModel.Postcode;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.Phone))
                        {
                            customer.TelephoneAndFaxNumber = profileModel.Phone;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.CVRNumber))
                        {
                            customer.CorporateIdentificationNumber = profileModel.CVRNumber;
                        }

                        // economic update
                        CustomerClient.UpdateCustomer(economicId, customer);
                    }

                    // brainless update
                    BrainLessUSChangeMemberInfo(profileModel, brainLessUserId);

                    // KimDamDev update
                    UmbracoChangePassword(profileModel, user);

                    TempData["success"] = true;

                    return(RedirectToCurrentUmbracoPage("?success=true"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, new Exception(string.Format("{0}", ex.Message)));
                }
            }

            TempData["success"] = false;

            return(CurrentUmbracoPage());
        }