private void MemberService_Saved(IMemberService sender, global::Umbraco.Core.Events.SaveEventArgs <IMember> e)
        {
            foreach (var member in e.SavedEntities)
            {
                if (string.IsNullOrEmpty(member.GetValue <string>(GlobalSettings.UmbracoSettings.MemberIdPropertyAlias)))
                {
                    var customer = new Customer.Customer()
                    {
                        roles = new List <int>()
                        {
                            3
                        },
                        FirstName = member.Name,
                        LastName  = "",
                        Password  = Guid.NewGuid().ToString(),
                        Email     = member.Email
                    };

                    string customerId;

                    if (string.IsNullOrEmpty(_userContext.CustomerId()))
                    {
                        customerId = _nopService.CreateCustomer(customer);
                        _userContext.SetCustomerId(int.Parse(customerId));
                    }
                    else
                    {
                        var nopCustomerId = _userContext.CustomerId();
                        customerId = _nopService.UpdateCustomer(customer, nopCustomerId);
                    }

                    member.SetValue(GlobalSettings.UmbracoSettings.MemberIdPropertyAlias, customerId);
                }
            }
        }
Ejemplo n.º 2
0
        public void CreateTemporalNopCustomer()
        {
            var customer = new Customer.Customer()
            {
                roles = new List <int>()
                {
                    3
                },
                FirstName = "Temp",
                LastName  = "Temp",
                Password  = Guid.NewGuid().ToString(),
                Email     = "*****@*****.**"
            };

            var customerId = _nopService.CreateCustomer(customer);

            _userContext.SetCustomerId(int.Parse(customerId));
        }