Esempio n. 1
0
        public async Task <ActionResult> Register(Register formModel)
        {
            var anonymousShoppingCart = WorkContext.CurrentCart;

            var user = new VirtoCommercePlatformCoreSecurityApplicationUserExtended
            {
                Email    = formModel.Email,
                Password = formModel.Password,
                UserName = formModel.Email,
            };

            var result = await _commerceCoreApi.StorefrontSecurityCreateAsync(user);

            if (result.Succeeded == true)
            {
                user = await _commerceCoreApi.StorefrontSecurityGetUserByNameAsync(user.UserName);

                var contact = new VirtoCommerceCustomerModuleWebModelContact
                {
                    Id     = user.Id,
                    Emails = new List <string> {
                        formModel.Email
                    },
                    FullName = string.Join(" ", formModel.FirstName, formModel.LastName),
                };

                if (string.IsNullOrEmpty(contact.FullName))
                {
                    contact.FullName = formModel.Email;
                }

                contact = await _customerApi.CustomerModuleCreateContactAsync(contact);

                await _commerceCoreApi.StorefrontSecurityPasswordSignInAsync(formModel.Email, formModel.Password);

                var identity = CreateClaimsIdentity(formModel.Email);
                _authenticationManager.SignIn(identity);

                await MergeShoppingCartsAsync(formModel.Email, anonymousShoppingCart);

                return(StoreFrontRedirect("~/account"));
            }
            else
            {
                ModelState.AddModelError("form", result.Errors.First());
            }

            return(View("customers/register", WorkContext));
        }
Esempio n. 2
0
 public async Task CreateCustomerAsync(CustomerInfo customer)
 {
     var contact = customer.ToServiceModel();
     await _customerApi.CustomerModuleCreateContactAsync(contact);
 }