Example #1
0
        private void SynchronizeProfile()
        {
            try
            {
                // Si esta conectado
                if (Connection.IsConnected)
                {
                    // Obtener el perfil remoto
                    CustomerClient customerClient = new CustomerClient(Connection.ServerBinding, new EndpointAddress(Connection.ServerUri + "Customer"));
                    CustomerEntity remoteCustomer = customerClient.GetCustomer(this.Customer.Id, true, Connection.Session);
                    // Y el perfil local
                    CustomerDataAccess customerDataAccess = new CustomerDataAccess();
                    CustomerEntity     localCustomer      = customerDataAccess.Load(this.Customer.Id, true);
                    // Si el perfil local es más nuevo que el remoto
                    if (localCustomer.Timestamp > remoteCustomer.Timestamp)
                    {
                        // Establecer los campos comunes
                        remoteCustomer.Name        = localCustomer.Name;
                        remoteCustomer.PhoneNumber = localCustomer.PhoneNumber;
                        remoteCustomer.Surname     = localCustomer.Surname;
                        remoteCustomer.UserName    = localCustomer.UserName;
                        remoteCustomer.Address     = localCustomer.Address;
                        // Establecer las preferencias
                        foreach (PreferenceEntity remotePreference in remoteCustomer.Preferences)
                        {
                            foreach (PreferenceEntity localPreference in localCustomer.Preferences)
                            {
                                if (remotePreference.IdCategory == localPreference.IdCategory)
                                {
                                    remotePreference.Active = localPreference.Active;
                                }
                            }
                        }

                        CustomerEntity returnCustomer = customerClient.Save(remoteCustomer, Connection.Session);
                        if (returnCustomer != null)
                        {
                            Debug.WriteLine("Internal application error saving remote customer.");
                        }
                        else
                        {
                            Debug.WriteLine("Remote customer updated.");
                        }
                    }
                }
            }
            catch (Exception error)
            {
                Debug.WriteLine("Error synchronizing profile. " + error.Message);
            }
        }
        public CustomerUpdateViewModel GetCustomer(Umbraco.Core.Models.IPublishedContent user)
        {
            int economicId = 0;

            if (user.Properties.FirstOrDefault(p => p.PropertyTypeAlias == ECONOMICID) != null && user.GetProperty(ECONOMICID).HasValue)
            {
                economicId = (int)user.GetProperty(ECONOMICID).Value;
            }
            else
            {
                throw new Exception("E-conomic er ikke blevet integreret. Kontakt os gerne, så vi kan løse problemet.");
            }

            var customer = CustomerClient.GetCustomer(economicId);

            var firstName = string.Empty;
            var lastName  = string.Empty;

            if (!string.IsNullOrWhiteSpace(customer.Name))
            {
                var n = customer.Name.Split(' ');
                firstName = n.First();

                if (n.Count() > 1)
                {
                    for (int i = 1; i < n.Count(); i++)
                    {
                        lastName += i == 1 ? n[i] : string.Format(" {0}", n[i]);
                    }
                }
            }

            return(new CustomerUpdateViewModel()
            {
                Address = customer.Address,
                City = customer.City,
                CompanyName = !string.IsNullOrWhiteSpace(customer.CorporateIdentificationNumber) ? customer.Name : string.Empty,
                FirstName = firstName,
                LastName = lastName,
                ConfirmEmail = customer.Email,
                Email = customer.Email,
                Country = customer.Country,
                CVRNumber = customer.CorporateIdentificationNumber,
                Phone = customer.TelephoneAndFaxNumber,
                Postcode = customer.Zip
            });
        }
Example #3
0
        /// <summary>
        /// Vuelve a cargar la información del desde el servidor.
        /// No controla si se esta conectado ni captura excepciones.
        /// </summary>
        internal void ReloadCustomer()
        {
            CustomerClient customerClient = new CustomerClient(Connection.ServerBinding, new System.ServiceModel.EndpointAddress(UtnEmall.Client.SmartClientLayer.Connection.ServerUri + "Customer"));

            this.Customer = customerClient.GetCustomer(this.Customer.Id, true, Connection.Session);
        }
 public void GetCustomer()
 {
     CustomerClient.GetCustomer(9);
 }
        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());
        }
Example #6
0
 // GET: Customer
 public ActionResult Index()
 {
     return(View(db.GetCustomer()));
 }