public async Task <CustomerResult> GetCustomer(Guid customerId)
        {
            Customer customer = _context
                                .Customers
                                .Where(e => e.Id == customerId)
                                .SingleOrDefault();

            if (customer == null)
            {
                throw new CustomerNotFoundException($"The customer {customerId} does not exists or is not processed yet.");
            }

            List <AccountResult> accountsResult = new List <AccountResult>();

            foreach (Guid accountId in customer.Accounts)
            {
                AccountResult accountResult = await _accountsQueries.GetAccount(accountId);

                accountsResult.Add(accountResult);
            }

            CustomerResult customerResult = new CustomerResult(
                customer.Id, customer.Name, customer.SSN,
                accountsResult);

            return(await Task.FromResult <CustomerResult>(customerResult));
        }
        public async Task <IActionResult> GetCustomer(Guid customerId)
        {
            CustomerResult customer = await _customerQueries.GetCustomer(customerId);

            if (customer == null)
            {
                return(new NoContentResult());
            }
            List <AccountDetailsModel> accounts = new List <AccountDetailsModel>();

            foreach (var account in customer.Accounts)
            {
                List <TransactionModel> transactions = new List <TransactionModel>();
                foreach (var item in account.Transactions)
                {
                    var transaction = new TransactionModel(
                        item.Amount,
                        item.Description,
                        item.TransactionDate);
                    transactions.Add(transaction);
                }
                accounts.Add(new AccountDetailsModel(
                                 account.AccountId,
                                 account.CurrentBalance,
                                 transactions));
            }

            CustomerDetailsModel model = new CustomerDetailsModel(
                customer.CustomerId,
                customer.PersonNummer,
                customer.Name,
                accounts);

            return(new ObjectResult(model));
        }
Esempio n. 3
0
        public ManagerResponse <CustomerResult, bool> SetPrimaryAddress(string userName, string addressExternalId)
        {
            Assert.ArgumentNotNullOrEmpty(addressExternalId, nameof(addressExternalId));

            var userPartiesResponse = GetCustomerParties(userName);

            if (userPartiesResponse.ServiceProviderResult.Success)
            {
                var customerResult = new CustomerResult {
                    Success = false
                };
                customerResult.SystemMessages.ToList().AddRange(userPartiesResponse.ServiceProviderResult.SystemMessages);
                return(new ManagerResponse <CustomerResult, bool>(customerResult, false));
            }

            var addressesToUpdate = new List <IParty>();

            var currentPrimary = userPartiesResponse.Result.SingleOrDefault(address => address.IsPrimary);

            if (currentPrimary != null)
            {
                currentPrimary.IsPrimary = false;
                addressesToUpdate.Add(currentPrimary);
            }

            var primaryAddress = userPartiesResponse.Result.Single(address => address.PartyId == addressExternalId);

            primaryAddress.IsPrimary = true;
            addressesToUpdate.Add(primaryAddress);

            var updatePartiesResponse = UpdateParties(userName, addressesToUpdate);

            return(new ManagerResponse <CustomerResult, bool>(updatePartiesResponse.ServiceProviderResult, updatePartiesResponse.Result));
        }
        public CustomerResult Find(long id)
        {
            Data.Entity.Customer entity = CustomerDao.Find(id);
            CustomerResult       result = CustomerResultConverter.Convert(entity);

            return(result);
        }
Esempio n. 5
0
        public ManagerResponse <CustomerResult, bool> RemovePartiesFromUser(string userName, string addressExternalId)
        {
            Assert.ArgumentNotNullOrEmpty(addressExternalId, nameof(addressExternalId));

            var getUserResponse = GetUser(userName);

            if (getUserResponse.Result == null)
            {
                var customerResult = new CustomerResult {
                    Success = false
                };
                customerResult.SystemMessages.ToList().AddRange(getUserResponse.ServiceProviderResult.SystemMessages);
                return(new ManagerResponse <CustomerResult, bool>(customerResult, false));
            }

            var customer = new CommerceCustomer {
                ExternalId = getUserResponse.Result.ExternalId
            };
            var parties = new List <CommerceParty> {
                new CommerceParty {
                    ExternalId = addressExternalId
                }
            };

            return(RemoveParties(customer, parties));
        }
Esempio n. 6
0
        public async Task <CustomerResult> GetCustomer(Guid customerId)
        {
            using (IDbConnection db = new SqlConnection(_connectionString))
            {
                string            customerSQL = "SELECT * FROM Customer WHERE Id = @customerId";
                Entities.Customer customer    = await db
                                                .QueryFirstOrDefaultAsync <Entities.Customer>(customerSQL, new { customerId });

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

                string             accountSQL = "SELECT id FROM Account WHERE CustomerId = @customerId";
                IEnumerable <Guid> accounts   = await db
                                                .QueryAsync <Guid>(accountSQL, new { customerId });

                List <AccountResult> accountCollection = new List <AccountResult>();

                foreach (Guid accountId in accounts)
                {
                    accountCollection.Add(await _accountsQueries.GetAccount(accountId));
                }

                CustomerResult customerResult = new CustomerResult(customer.Id,
                                                                   customer.Name,
                                                                   customer.SSN,
                                                                   accountCollection);

                return(customerResult);
            }
        }
        public CustomerResult Get(int size = 100, int page = 0)
        {
            serviceCaller.size = size;
            serviceCaller.from = page;
            CustomerResult result = new CustomerResult();

            var lstResult = new List <GetCustomerResult>();
            var response  = serviceCaller.SearchForGivenInput();
            var objResult = JsonConvert.DeserializeObject <PurchaseOrderResult>(response.Result);

            if (objResult != null && objResult.hits != null & objResult.hits.hits != null)
            {
                var group = (from p in objResult.hits.hits.ToList()

                             group p by new { p._source.ThreadID, p._source.PONumber } into g
                             select new { ThreadId = g.Key.ThreadID, PONumber = g.Key.PONumber, POResult = g.ToList() }).ToList();

                foreach (var item in group)
                {
                    var lstOfSteps = purchaseOrderStatusRetriever.GetSteps(item.POResult.ToList());
                    var identity   = item.POResult.First()._source.Identity;

                    lstResult.Add(new GetCustomerResult
                    {
                        ProfileID  = identity,
                        lstOfSteps = lstOfSteps,
                        PONumber   = item.PONumber,
                        ThreadID   = item.ThreadId
                    });
                }
                result.Total = objResult.hits.total;
                result.lst   = lstResult;
            }
            return(result);
        }
        public async Task <CustomerResult> GetCustomer(Guid customerId)
        {
            Customer customer = await _context
                                .Customers
                                .Find(e => e.Id == customerId)
                                .SingleOrDefaultAsync();

            if (customer == null)
            {
                throw new CustomerNotFoundException($"The customer {customerId} does not exists or is not processed yet.");
            }

            List <Guid> accountIds = await _context
                                     .Accounts
                                     .Find(e => e.CustomerId == customerId)
                                     .Project(p => p.Id)
                                     .ToListAsync();

            List <AccountResult> accountsResult = new List <AccountResult>();

            foreach (Guid accountId in accountIds)
            {
                AccountResult accountResult = await _accountsQueries.GetAccount(accountId);

                accountsResult.Add(accountResult);
            }

            CustomerResult customerResult = new CustomerResult(
                customer.Id, customer.Name, customer.SSN,
                accountsResult);

            return(customerResult);
        }
Esempio n. 9
0
        private void Button1_Click(object sender, EventArgs e)
        {
            this.button1.Enabled = false;

            PagingInfo pagingInfo = new PagingInfo
            {
                PageNumber = 1,
                PageSize   = 5,
            };

            // this loop simulates some delays in processing
            for (int iter = 0; iter < 100; iter += pagingInfo.PageSize) // just using pageSize to randomize the effec a bit
            {
                Thread.Sleep(700);
            }



            CustomerRepository cr  = new CustomerRepository("connection string");
            CustomerResult     res = cr.GetCustomers(pagingInfo);

            this.button1.Enabled = true;

            string serializedCustomers = JsonConvert.SerializeObject(res, Formatting.Indented);

            this.richTextBox1.Text += $"{serializedCustomers} {Environment.NewLine}{Environment.NewLine}";
        }
Esempio n. 10
0
        /// <summary>
        /// Removes the parties from current user.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="visitorContext">The visitor context.</param>
        /// <param name="addressExternalId">The address external identifier.</param>
        /// <returns>
        /// The manager response with the successflag in the Result.
        /// </returns>
        public virtual ManagerResponse <CustomerResult, bool> RemovePartiesFromCurrentUser([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, [NotNull] string addressExternalId)
        {
            Assert.ArgumentNotNull(storefront, "storefront");
            Assert.ArgumentNotNull(visitorContext, "visitorContext");
            Assert.ArgumentNotNullOrEmpty(addressExternalId, "addresseExternalId");

            var getUserResponse = this.GetUser(Context.User.Name);

            if (getUserResponse.Result == null)
            {
                var customerResult = new CustomerResult {
                    Success = false
                };
                customerResult.SystemMessages.ToList().AddRange(getUserResponse.ServiceProviderResult.SystemMessages);
                return(new ManagerResponse <CustomerResult, bool>(customerResult, false));
            }

            var customer = new CommerceCustomer {
                ExternalId = getUserResponse.Result.ExternalId
            };
            var parties = new List <CommerceParty> {
                new CommerceParty {
                    ExternalId = addressExternalId
                }
            };

            return(this.RemoveParties(storefront, customer, parties));
        }
        public async Task <CustomerResult> GetCustomer(Guid customerId)
        {
            Entities.Customer customer = await _context
                                         .Customers
                                         .FindAsync(customerId);

            List <Entities.Account> accounts = await _context
                                               .Accounts
                                               .Where(e => e.CustomerId == customerId)
                                               .ToListAsync();

            if (customer == null)
            {
                throw new CustomerNotFoundException($"The customer {customerId} does not exists or is not processed yet.");
            }

            List <AccountResult> accountsResult = new List <AccountResult>();

            foreach (Account account in accounts)
            {
                AccountResult accountResult = await _accountsQueries.GetAccount(account.Id);

                accountsResult.Add(accountResult);
            }

            CustomerResult customerResult = new CustomerResult(
                customer.Id, customer.Name, customer.SSN,
                accountsResult);

            return(await Task.FromResult <CustomerResult>(customerResult));
        }
Esempio n. 12
0
        public async Task <CustomerResult> Get(Guid id)
        {
            var customer = await customerReadOnlyRepository.Get(id);

            CustomerResult customerResult = resultConverter.Map <CustomerResult>(customer);

            return(customerResult);
        }
        public CustomerResult Post(ExportToExcelInput input)
        {
            string startDate      = input.StartDate;
            string endDate        = input.EndDate;
            string customerNumber = input.CustomerNumber;
            int    size           = input.Size == 0 ? 100 : input.Size;
            int    page           = input.Page;
            string threadID       = !(string.IsNullOrEmpty(input.ThreadId)) ? input.ThreadId : "";
            string poNumber       = !(string.IsNullOrEmpty(input.PONumber)) ? input.PONumber : "";


            serviceCaller.size = size;
            serviceCaller.from = page;

            CustomerResult result    = new CustomerResult();
            var            lstResult = new List <GetCustomerResult>();

            var pos             = serviceCaller.GetPOS(input);
            var poNumbersSource = JsonConvert.DeserializeObject <PurchaseOrderResult>(pos.Result);
            var poNumbers       = poNumbersSource.hits.hits.Where(x => x._source.ThreadID != null).Select(x => x._source.ThreadID).ToList();

            result.Total = poNumbersSource.hits.total;
            var response  = serviceCaller.SearchForGivenInput(startDate, endDate, customerNumber, poNumbers, threadID: threadID);
            var objResult = JsonConvert.DeserializeObject <PurchaseOrderResult>(response.Result);

            if (objResult != null && objResult.hits != null & objResult.hits.hits != null)
            {
                //int total = objResult.hits.total;
                //response = serviceCaller.SearchForGivenInput(startDate, endDate, customerNumber, poNumbers, total);
                //objResult = JsonConvert.DeserializeObject<PurchaseOrderResult>(response.Result);
                if (objResult != null && objResult.hits != null & objResult.hits.hits != null)
                {
                    var group = (from p in objResult.hits.hits.ToList()

                                 //where string.IsNullOrEmpty(id) || p._source.Identity.Contains(id)
                                 group p by new { ThreadID = p._source.ThreadID } into g
                                 select new { ThreadId = g.Key.ThreadID, POResult = g.ToList() }).ToList();

                    foreach (var item in group)
                    {
                        var lstOfSteps = purchaseOrderStatusRetriever.GetSteps(item.POResult.ToList());
                        var po         = item.POResult.Where(x => !string.IsNullOrEmpty(x._source.PONumber)).Count() > 0 ? item.POResult.Where(x => !string.IsNullOrEmpty(x._source.PONumber)).FirstOrDefault()._source.PONumber : "";
                        var identity   = item.POResult.Where(x => x._source != null && x._source.Identity != null).FirstOrDefault();
                        lstResult.Add(new GetCustomerResult
                        {
                            ProfileID  = identity != null ? identity._source.Identity : "",
                            lstOfSteps = lstOfSteps,
                            PONumber   = po,
                            ThreadID   = item.ThreadId
                        });
                    }
                    //result.Total = objResult.hits.total;
                    result.lst = lstResult;
                }
            }
            return(result);
        }
Esempio n. 14
0
        public async Task <CustomerResult> Process(UpdateCustomerCommand command)
        {
            Domain.Customers.Customer customer = new Domain.Customers.Customer(command.CustomerId, command.Name, command.LastName, command.Document, command.Celphone, command.Address);

            await customerWriteOnlyRepository.Update(customer);

            CustomerResult customerResult = resultConverter.Map <CustomerResult>(customer);

            return(customerResult);
        }
Esempio n. 15
0
        private void _getCustomersWorker3_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            bool inError = (e.Error != null);

            CustomerResult res = (e.Result as CustomerResult) ?? new CustomerResult {
                Customers = new List <Customer>()
            };

            DisplayWorkResult(res, inError);
        }
        public JsonResult Create(Customer model, out int CusId)
        {
            CustomerResult result = ApiHelper <CustomerResult> .HttpPostAsync(
                $"{Helper.ApiUrl}api/Customer/Create",
                model
                );

            CusId = result.CusId;
            return(Json(new { result }));
        }
Esempio n. 17
0
        public void ModelIsPassedIntoIfSuccess()
        {
            var result = new CustomerResult { FirstName = "Bob" };

            GivenController.As<UserController>()
                .ShouldRenderView(RestfulAction.New)
                .Should(x => x.AssertResultIs<ViewResult>().ViewData.Model.ShouldNotBeNull())
                .IfCallSucceeds(result)
                .WhenCalling(x => x.CreateWithModel());
        }
        public ManagerResponse <CustomerResult, IEnumerable <Party> > RemoveParties(CommerceCustomer customer, IEnumerable <Party> parties)
        {
            Assert.ArgumentNotNull(customer, nameof(customer));
            Assert.ArgumentNotNull(parties, nameof(parties));

            var removePartiesRequest = new RemovePartiesRequest(customer, parties.ToList());

            CustomerResult removePartiesResult = this.customerServiceProvider.RemoveParties(removePartiesRequest);

            return(new ManagerResponse <CustomerResult, IEnumerable <Party> >(removePartiesResult, null));
        }
Esempio n. 19
0
        public CustomerResult SearchCustomer(CustomerInput input)
        {
            var customers = new CustomerResult();

            using (var connection = new SqlConnection(connectionString))
            {
                customers = connection.QueryFirstOrDefault <CustomerResult>(@"
                SELECT CustomerID,CustomerName,CustomerLastName,Location 
                FROM Customer (nolock) WHERE  CustomerID = @CustomerID", new { CustomerID = input.CustomerID });
            }
            return(customers);
        }
        public void ModelIsPassedIntoIfSuccess()
        {
            var result = new CustomerResult {
                FirstName = "Bob"
            };

            GivenController.As <UserController>()
            .ShouldRenderView(RestfulAction.New)
            .Should(x => x.AssertResultIs <ViewResult>().ViewData.Model.ShouldNotBeNull())
            .IfCallSucceeds(result)
            .WhenCalling(x => x.CreateWithModel());
        }
Esempio n. 21
0
        public void AddGraphTypeFields(QueryCore queryCore)
        {
            queryCore.FieldAsync <CustomerResultType>(name: "customerLoyalty",
                                                      description: null,
                                                      resolve: async context =>
            {
                var startQuery = context?.Operation?
                                 .SelectionSet?
                                 .Selections
                                 .Select(x => x as Field)
                                 .FirstOrDefault();


                var fields = startQuery?.SelectionSet?
                             .Selections
                             .Select(x => x as Field)
                             .ToList();
                var prizesField = fields?
                                  .Where(x => "prizes".EqualsNoCase(x.Name))
                                  .FirstOrDefault();


                var userContext = context.UserContext.As <GraphQLUserContext>();
                var user        = userContext.HttpContextAccessor.HttpContext.User;
                var query       = from item in user.Claims
                                  where item.Type == ClaimTypes.NameIdentifier
                                  select item;
                if (query.Any())
                {
                    var claim          = query.First();
                    var userId         = claim.Value;
                    var customer       = await _customerLoyaltyStore.GetCustomerAsync(userId);
                    var customerResult = new CustomerResult
                    {
                        ID = customer.ID,
                        LoyaltyPointBalance = customer.LoyaltyPointBalance
                    };

                    if (prizesField != null)
                    {
                        var prizeStore = _lazyPrizeStore;
                        var prizes     =
                            await prizeStore.GetAvailablePrizesAsync(customer.LoyaltyPointBalance);
                        customerResult.Prizes = prizes;
                    }

                    return(customerResult);
                }
                return(null);
            },
                                                      deprecationReason: null);
        }
Esempio n. 22
0
        public async Task <CustomerResult> GetCustomer(Guid id)
        {
            Customer data = await mongoDB
                            .Customers
                            .Find(e => e.Id == id)
                            .SingleOrDefaultAsync();

            if (data == null)
            {
                throw new CustomerNotFoundException($"The customer {id} does not exists or is not processed yet.");
            }

            //
            // TODO: The following queries could be simplified
            //

            List <AccountResult> accounts = new List <AccountResult>();

            foreach (var accountId in data.Accounts.Items)
            {
                Account account = await mongoDB
                                  .Accounts
                                  .Find(e => e.Id == accountId)
                                  .SingleOrDefaultAsync();

                if (account == null)
                {
                    throw new CustomerNotFoundException($"The account {accountId} does not exists or is not processed yet.");
                }

                //
                // TODO: The "Accout closed state" is not propagating to the Customer Aggregate
                //

                if (account != null)
                {
                    AccountResult accountOutput = resultConverter.Map <AccountResult>(account);
                    accounts.Add(accountOutput);
                }
            }

            CustomerResult customerResult = resultConverter.Map <CustomerResult>(data);

            customerResult = new CustomerResult(
                customerResult.CustomerId,
                customerResult.Personnummer,
                customerResult.Name,
                accounts);

            return(customerResult);
        }
        public OrderSelectCustomerViewModel(ICustomerService customerService, INavigator navigator)
        {
            Application.Current.MainWindow.Width  = 300;
            Application.Current.MainWindow.Height = 250;

            _navigator       = navigator;
            _customerService = customerService;

            SelectedCustomer = new CustomerResult();

            _ = LoadData();

            InstantiateCommands();
        }
Esempio n. 24
0
        public async Task <CustomerResult> GetCustomerAsync(Guid id, CancellationToken cancellationToken = default)
        {
            //Customer customer = await Context.Customers.FindAsync(id, cancellationToken);
            Customer customer = await Context.Customers.SingleOrDefaultAsync(c => c.CustomerId == id, cancellationToken);

            if (customer == null)
            {
                throw new SqlNullValueException($"The customer {id} does not exists or is not processed yet ..");
            }

            CustomerResult customerResult = RsultConverter.Map <CustomerResult>(customer);

            return(customerResult);
        }
Esempio n. 25
0
        public async Task <CustomerResult> GetCustomer(Guid id)
        {
            Customer data = await this.mongoDB.Customers
                            .Find(Builders <Customer> .Filter.Eq("_id", id))
                            .SingleOrDefaultAsync();

            if (data == null)
            {
                throw new CustomerNotFoundException($"The account {id} does not exists or is not processed yet.");
            }

            CustomerResult customerVM = this.mapper.Map <CustomerResult>(data);

            return(customerVM);
        }
Esempio n. 26
0
        public OrderBeheerViewModel(ICustomerService customerService, IArticleService articleService, INavigator navigator, IOrderService orderService)
        {
            Application.Current.MainWindow.Width  = 1280;
            Application.Current.MainWindow.Height = 720;

            _customerService = customerService;
            _orderService    = orderService;
            _customer        = Customer;
            _navigator       = navigator;

            _articleService = articleService;

            _ = LoadData();

            InstantiateCommands();
        }
        public void ShouldHandleInvalidCustomerId()
        {
            var request = new UpdatePartiesRequest(
                new CommerceCustomer {
                ExternalId = "1234"
            },
                new List <Party>(0)
                );
            var result = new CustomerResult();
            var args   = new ServicePipelineArgs(request, result);

            _processor.Process(args);

            result.Success.Should().Be(false);
            result.SystemMessages.Should().HaveCount(x => x > 0);
        }
        public void RegisterCustomer__Return_Customer__When_Details_Are_Valid()
        {
            //
            // Arrange
            string expectName                   = "John Doe";
            string expectedPhoneNumber          = "+76 1 400 180 66";
            IRegisterCustomerUseCase registerUC = new RegisterCustomerUseCase();

            // Act
            CustomerResult actualCustomerResult = registerUC.Register(expectName, expectedPhoneNumber);

            // Assert
            Assert.NotNull(actualCustomerResult);
            Assert.NotEqual(Guid.Empty, actualCustomerResult.Id);
            Assert.Equal(expectName, actualCustomerResult.Name);
            Assert.Equal(expectedPhoneNumber, actualCustomerResult.PhoneNumber);
        }
Esempio n. 29
0
        public void Register__Return_Customer__When_Details_Are_Valid()
        {
            //
            //Arrange
            string expectName        = "Wesley Santos";
            string expectPhoneNumber = "+55 31 9 9475 6634";

            IRegisterCustomerUseCase registerUc = new RegisterCustomerUseCase();

            //Act
            CustomerResult actualCustomerResult = registerUc.Register(expectName, expectPhoneNumber);

            //Assert
            Assert.NotNull(actualCustomerResult);
            Assert.NotEqual(Guid.Empty, actualCustomerResult.Id);
            Assert.Equal(expectName, actualCustomerResult.Name);
            Assert.Equal(expectPhoneNumber, actualCustomerResult.PhoneNumber);
        }
Esempio n. 30
0
        public ActionResult Edit(CustomerResult model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var result = RestIntegration.Put <CustomerResult, ApiReturnList <CustomerResult> >("http://localhost:54878/", "/api/Customers", model);

                    return(RedirectToAction(nameof(Index)));
                }

                return(View(model));
            }
            catch (Exception e)
            {
                return(View(model));
            }
        }
        public void RegisterCustomer__Returns_Customer__When_Input_Are_Valid()
        {
            //
            // Arrange
            string expectName        = "Silas Caxias";
            string expectPhoneNumber = "+55 19 997236192";

            IRegisterCustomerUseCase registerUC = new RegisterCustomerUseCase();

            // Act
            CustomerResult actualCustomerResult = registerUC.Register(expectName, expectPhoneNumber);

            // Assert
            Assert.NotNull(actualCustomerResult);
            Assert.NotEqual(Guid.Empty, actualCustomerResult.Id);
            Assert.Equal(expectName, actualCustomerResult.Name);
            Assert.Equal(expectPhoneNumber, actualCustomerResult.PhoneNumber);
        }
        /// <summary>
        /// Removes the parties from current user.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="visitorContext">The visitor context.</param>
        /// <param name="addressExternalId">The address external identifier.</param>
        /// <returns>
        /// The manager response with the successflag in the Result.
        /// </returns>
        public virtual ManagerResponse<CustomerResult, bool> RemovePartiesFromCurrentUser([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, [NotNull] string addressExternalId)
        {
            Assert.ArgumentNotNull(storefront, "storefront");
            Assert.ArgumentNotNull(visitorContext, "visitorContext");
            Assert.ArgumentNotNullOrEmpty(addressExternalId, "addresseExternalId");

            var getUserResponse = this.GetUser(Context.User.Name);
            if (getUserResponse.Result == null)
            {
                var customerResult = new CustomerResult { Success = false };
                customerResult.SystemMessages.ToList().AddRange(getUserResponse.ServiceProviderResult.SystemMessages);
                return new ManagerResponse<CustomerResult, bool>(customerResult, false);
            }

            var customer = new CommerceCustomer { ExternalId = getUserResponse.Result.ExternalId };
            var parties = new List<CommerceParty> { new CommerceParty { ExternalId = addressExternalId } };

            return this.RemoveParties(storefront, customer, parties);
        }
        /// <summary>
        /// Sets the primary address.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="visitorContext">The visitor context.</param>
        /// <param name="addressExternalId">The address external identifier.</param>
        /// <returns>The manager responsed with the success flag in the result.</returns>
        public virtual ManagerResponse<CustomerResult, bool> SetPrimaryAddress([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, [NotNull]string addressExternalId)
        {
            Assert.ArgumentNotNull(storefront, "storefront");
            Assert.ArgumentNotNull(visitorContext, "visitorContext");
            Assert.ArgumentNotNullOrEmpty(addressExternalId, "addressExternalId");

            var userPartiesResponse = this.GetCurrentCustomerParties(storefront, visitorContext);
            if (userPartiesResponse.ServiceProviderResult.Success)
            {
                var customerResult = new CustomerResult { Success = false };
                customerResult.SystemMessages.ToList().AddRange(userPartiesResponse.ServiceProviderResult.SystemMessages);
                return new ManagerResponse<CustomerResult, bool>(customerResult, false);
            }

            var addressesToUpdate = new List<CSFConnectModels.CommerceParty>();

            CSFConnectModels.CommerceParty notPrimary = (CSFConnectModels.CommerceParty)userPartiesResponse.Result.SingleOrDefault(address => ((CSFConnectModels.CommerceParty)address).IsPrimary);
            if (notPrimary != null)
            {
                notPrimary.IsPrimary = false;
                addressesToUpdate.Add(notPrimary);
            }

            var primaryAddress = (CSFConnectModels.CommerceParty)userPartiesResponse.Result.Single(address => address.PartyId == addressExternalId);

            //primaryAddress.IsPrimary = true;
            addressesToUpdate.Add(primaryAddress);

            var updatePartiesResponse = this.UpdateParties(storefront, new CommerceCustomer { ExternalId = visitorContext.UserId }, addressesToUpdate.Cast<Party>().ToList());

            return new ManagerResponse<CustomerResult, bool>(updatePartiesResponse.ServiceProviderResult, updatePartiesResponse.Result);
        }