public virtual async Task <IHttpActionResult> UpdateAccountAsync(EditAccountRequest request)
        {
            var param = new UpdateAccountParam
            {
                CustomerId        = ComposerContext.CustomerId,
                Scope             = ComposerContext.Scope,
                PreferredLanguage = request.PreferredLanguage,
                Email             = request.Email,
                FirstName         = request.FirstName,
                LastName          = request.LastName,
                CultureInfo       = ComposerContext.CultureInfo,
            };

            var urlParam = new BaseUrlParameter {
                CultureInfo = param.CultureInfo
            };
            var addressListUrl    = MyAccountUrlProvider.GetAddressListUrl(urlParam);
            var changePasswordUrl = MyAccountUrlProvider.GetChangePasswordUrl(urlParam);

            var viewModel = await CustomerViewService.UpdateAccountAsync(param);

            if (viewModel == null)
            {
                return(Unauthorized());
            }

            viewModel.AddressListUrl    = addressListUrl;
            viewModel.ChangePasswordUrl = changePasswordUrl;

            return(Ok(viewModel));
        }
 protected virtual void UpdateCustomerInfo(Customer customer, UpdateAccountParam updateParam)
 {
     customer.Email     = updateParam.Email;
     customer.FirstName = updateParam.FirstName;
     customer.LastName  = updateParam.LastName;
     customer.Language  = updateParam.PreferredLanguage;
 }
Beispiel #3
0
        public void WHEN_Customer_is_Null_SHOULD_throw_ArgumentException()
        {
            //Arrange
            var customerViewService = _container.CreateInstance <CustomerViewService>();
            var param = new UpdateAccountParam
            {
                ReturnUrl         = GetRandom.String(32),
                Scope             = GetRandom.String(32),
                CultureInfo       = TestingExtensions.GetRandomCulture(),
                Email             = GetRandom.String(32),
                FirstName         = GetRandom.String(32),
                LastName          = GetRandom.String(32),
                PreferredLanguage = GetRandom.String(4),
            };

            //Act
            var ex = Assert.ThrowsAsync <ArgumentException>(() => customerViewService.UpdateAccountAsync(param));

            //Assert
            ex.Message.Should().ContainEquivalentOf("Customer");
        }
        /// <summary>
        /// Update the account informations.
        /// </summary>
        /// <param name="param">Builder params <see cref="UpdateAccountParam"/></param>
        /// <returns></returns>
        public async virtual Task <UpdateAccountViewModel> UpdateAccountAsync(UpdateAccountParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param));
            }
            if (param.CustomerId == Guid.Empty)
            {
                throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.Email))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Email)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.FirstName))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.FirstName)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.LastName))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.LastName)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.PreferredLanguage))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.PreferredLanguage)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param));
            }

            var customer = await CustomerRepository.GetCustomerByIdAsync(new GetCustomerByIdParam
            {
                Scope       = param.Scope,
                CustomerId  = param.CustomerId,
                CultureInfo = param.CultureInfo
            }).ConfigureAwait(false);

            if (customer == null)
            {
                return(null);
            }

            UpdateCustomerInfo(customer, param);

            var updateUserParam = new UpdateUserParam
            {
                Customer = customer,
                Scope    = param.Scope
            };

            var updatedCustomer = await CustomerRepository.UpdateUserAsync(updateUserParam).ConfigureAwait(false);

            var getUpdateAccountViewModelParam = new GetUpdateAccountViewModelParam
            {
                Status      = MyAccountStatus.Success,
                CultureInfo = param.CultureInfo,
                ReturnUrl   = param.ReturnUrl
            };

            return(GetUpdateAccountViewModel(getUpdateAccountViewModelParam, updatedCustomer));
        }