Esempio n. 1
0
        public async Task <IEnumerable <CustomerAccount> > GetCustomerAccounts(int?startIndex, int?pageSize, string sortBy = null, string filter = null)
        {
            var customerAccountResource = new CustomerAccountResource(_apiContext);
            var accounts = await customerAccountResource.GetAccountsAsync(startIndex, pageSize, sortBy, filter, null);

            return(accounts.Items);
        }
Esempio n. 2
0
        public async Task <CustomerAuthTicket> AddCustomerAccount(CustomerAccountAndAuthInfo account, Credit credit, Wishlist wishlist)
        {
            var notes = new List <string>();

            var customerAccountResource = new CustomerAccountResource(_apiContext);
            var newAccount = await customerAccountResource.AddAccountAndLoginAsync(account);

            notes.Add(string.Format("updatedby:{0},updatedDate:{1},action:{2}", newAccount.CustomerAccount.
                                    AuditInfo.UpdateBy, newAccount.CustomerAccount.AuditInfo.UpdateDate, "AddAccountAndLoginAsync"));

            var customerContactResource = new CustomerContactResource(_apiContext);

            foreach (var contact in account.Account.Contacts)
            {
                contact.AccountId = newAccount.CustomerAccount.Id;
                var newContact = await customerContactResource.AddAccountContactAsync(contact,
                                                                                      newAccount.CustomerAccount.Id);

                notes.Add(string.Format("updatedby:{0},updatedDate:{1},action:{2}", newAccount.CustomerAccount.
                                        AuditInfo.UpdateBy, newAccount.CustomerAccount.AuditInfo.UpdateDate, "AddAccountContactAsync"));
            }

            var customerCreditResource = new CreditResource(_apiContext);

            credit.CustomerId = newAccount.CustomerAccount.Id;
            var newCredit = await customerCreditResource.AddCreditAsync(credit);

            notes.Add(string.Format("updatedby:{0},updatedDate:{1},action:{2}", newAccount.CustomerAccount.
                                    AuditInfo.UpdateBy, newAccount.CustomerAccount.AuditInfo.UpdateDate, "AddCreditAsync"));


            var wishListItemResource = new WishlistResource(_apiContext);

            wishlist.CustomerAccountId = newAccount.CustomerAccount.Id;
            var newWishList = await wishListItemResource.CreateWishlistAsync(wishlist);

            notes.Add(string.Format("updatedby:{0},updatedDate:{1},action:{2}", newAccount.CustomerAccount.
                                    AuditInfo.UpdateBy, newAccount.CustomerAccount.AuditInfo.UpdateDate, "CreateWishlistAsync"));


            var customerSegmentResource =
                new Mozu.Api.Resources.Commerce.Customer.CustomerSegmentResource(_apiContext);

//            var segmentAccount = await customerSegmentResource.AddSegmentAccountsAsync()

            var customerNoteResource = new CustomerNoteResource(_apiContext);

            foreach (var note in notes)
            {
                var newNote = await customerNoteResource.AddAccountNoteAsync(
                    new CustomerNote()
                {
                    Content = note
                },
                    newAccount.CustomerAccount.Id);
            }

            return(newAccount);
        }
        private IDictionary <string, CustomerAccount> LoadExistingAccounts(bool loadAllUsers)
        {
            _existingAccounts = new Dictionary <string, CustomerAccount>();

            var customerAccountResource = new CustomerAccountResource(Context.ApiContext);

            // change the start value by the page size until the start value is greater than the total

            var pageSize  = 20;
            var pageCount = 1;

            ReportProgress("Begin GetAccounts call at " + DateTime.Now.ToShortTimeString());
            var customerAccounts = customerAccountResource.GetAccounts(null, pageSize);

            ReportProgress("Finish GetAccounts call at " + DateTime.Now.ToShortTimeString());

            var addedCount   = 0;
            var skippedCount = 0;

            ReportProgress("Begin GetAccounts page " + pageCount + " call at " + DateTime.Now.ToShortTimeString());
            // skip paging for testing - comment out this for loop and its brackets - driven by checkbox on UI
            // skips loading all customer accounts into memory since it takes 3 hours on a production tenant with 39,000 users
            var upperLimit = 2;

            if (loadAllUsers)
            {
                upperLimit = customerAccounts.TotalCount;
            }
            for (pageCount = 1; pageCount < upperLimit; pageCount = pageCount + customerAccounts.PageSize)
            {
                customerAccounts = customerAccountResource.GetAccounts(pageCount, pageSize);

                foreach (CustomerAccount account in customerAccounts.Items)
                {
                    // Add to accountid lookup dictionary
                    //_existingAccounts.Add(account.Id.ToString(), account);
                    string userName = account.UserName;
                    if (string.IsNullOrEmpty(userName))
                    {
                        userName = account.EmailAddress;
                    }

                    if (!string.IsNullOrEmpty(userName) & !_existingAccounts.ContainsKey(userName.ToLower()))
                    {
                        _existingAccounts.Add(userName.ToLower(), account);
                        addedCount++;
                    }
                    else
                    {
                        skippedCount++;
                        ReportProgress("skipping " + account.UserId + ":" + account.UserName + " - " + account.FirstName + " " + account.LastName + " with email address of " + account.EmailAddress);
                    }
                }
            }
            ReportProgress("Finish GetAccounts page " + pageCount + " call at " + DateTime.Now.ToShortTimeString());

            return(_existingAccounts);
        }
Esempio n. 4
0
        public async Task <CustomerAuthTicket> AddCustomerAccount(int tenantId, int?siteId,
                                                                  int?masterCatalogId, CustomerAccountAndAuthInfo account)
        {
            _apiContext = new ApiContext(tenantId, siteId);

            var customerAccountResource = new CustomerAccountResource(_apiContext);
            var newAccount = await customerAccountResource.AddAccountAndLoginAsync(account);

            return(newAccount);
        }
Esempio n. 5
0
        public async Task <CustomerAccount> GetCustomerAccount(int tenantId, int?siteId,
                                                               int?masterCatalogId, int accountId)
        {
            _apiContext = new ApiContext(tenantId, siteId, masterCatalogId);

            var customerAccountResource = new CustomerAccountResource(_apiContext);
            var account = await customerAccountResource.GetAccountAsync(accountId);

            return(account);
        }
Esempio n. 6
0
        protected async override Task <bool> GetDataAsync()
        {
            var resource = new CustomerAccountResource(Context);

            _results = await resource.GetCustomersPurchaseOrderAccountsAsync(startIndex : StartIndex, pageSize : PageSize, sortBy : SortBy, responseFields : ResponseFields);

            TotalCount = _results.TotalCount;
            PageCount  = _results.PageCount;
            PageSize   = _results.PageSize;
            return(_results.Items != null && _results.Items.Count > 0);
        }
Esempio n. 7
0
        public async Task <CustomerAccount> UpdateCustomerAccount(int tenantId, int?siteId,
                                                                  int?masterCatalogId, CustomerAccount account)
        {
            _apiContext = new ApiContext(tenantId, siteId, masterCatalogId);

            var customerAccountResource = new CustomerAccountResource(_apiContext);
            var updatedAccount          = await customerAccountResource.UpdateAccountAsync(account,
                                                                                           account.Id);

            return(updatedAccount);
        }
        protected override async Task <bool> GetDataAsync()
        {
            var resource = new CustomerAccountResource(Context);

            _results = await resource.GetAccountsAsync(startIndex : StartIndex, pageSize : PageSize, sortBy : SortBy, filter : Filter, q : Q, qLimit : QLimit, responseFields : ResponseFields);

            TotalCount = _results.TotalCount;
            PageCount  = _results.PageCount;
            PageSize   = _results.PageSize;
            return(_results.Items != null && _results.Items.Count > 0);
        }
        private void DeleteCustomer(CustomerModel customer)
        {
            if (customer.Delete == false)
            {
                throw new Exception("Will not delete account because it is not marked for deletion");
            }

            // Delete the customer Account
            var customerAccountResource = new CustomerAccountResource(Context.ApiContext);

            customerAccountResource.DeleteAccount(customer.Account.Id);
        }
        private IDictionary <string, CustomerAccount> LoadExistingAccounts()
        {
            _existingAccounts = new Dictionary <string, CustomerAccount>();

            var customerAccountResource = new CustomerAccountResource(Context.ApiContext);
            var customerAccounts        = customerAccountResource.GetAccounts();

            foreach (CustomerAccount account in customerAccounts.Items)
            {
                // Add to accountid lookup dictionary
                //_existingAccounts.Add(account.Id.ToString(), account);
                if (!string.IsNullOrEmpty(account.UserName))
                {
                    _existingAccounts.Add(account.UserName, account);
                }
            }
            return(_existingAccounts);
        }
        private void CreateCustomer(CustomerModel customer)
        {
            // Create or Update the customerAccount
            var customerAccountResource = new CustomerAccountResource(Context.ApiContext);

            var existingAccount = ExistingAccount(customer.Account.UserName);

            if (existingAccount != null)
            {
                // Update existing account
                customer.Account.Id = existingAccount.Id;

                customer.Account = customerAccountResource.UpdateAccount(customer.Account, customer.Account.Id);
                ReportProgress("Account updated: " + customer.Account.Id);
            }
            else
            {
                // Add a new account
                customer.Account = customerAccountResource.AddAccount(customer.Account);
                ReportProgress("Account created: " + customer.Account.Id + " " + customer.Account.UserName);
            }

            // Set the password only if we have one
            if (!string.IsNullOrEmpty(customer.Password))
            {
                var loginInfo = new CustomerLoginInfo();
                loginInfo.EmailAddress = customer.Account.EmailAddress;
                loginInfo.IsImport     = true;
                loginInfo.Username     = customer.Account.UserName;
                loginInfo.Password     = customer.Password;
                var customerAuth = customerAccountResource.AddLoginToExistingCustomer(loginInfo, customer.Account.Id);
                ReportProgress("Password Updated for : " + customer.Account.Id);
            }

            foreach (var contact in customer.Contacts)
            {
                // Update or Create the customer contact as required
                var customerContactResource = new CustomerContactResource(Context.ApiContext);

                // Find the existing contact of this type.
                CustomerContact existingContact = null;
                if (customer.Account.Contacts != null)
                {
                    foreach (var cc in customer.Account.Contacts)
                    {
                        foreach (var t in cc.Types)
                        {
                            if (t.Name == contact.Types[0].Name)
                            {
                                existingContact = cc;
                                break; // out
                            }
                            if (existingContact != null)
                            {
                                break; // out
                            }
                        }
                    }
                }

                if (existingContact != null)
                {
                    // update the existing contact
                    contact.Id = existingContact.Id;
                    customerContactResource.UpdateAccountContact(contact, customer.Account.Id, existingContact.Id);
                    ReportProgress("contact Updated: " + contact.Id + " " + contact.Email);
                }
                else
                {
                    // create a new contact
                    var newContact = customerContactResource.AddAccountContact(contact, customer.Account.Id);
                    ReportProgress("Contact Created Id: " + newContact.Id + " for " + newContact.Email);
                }
            }
        }
Esempio n. 12
0
        public async Task <CustomerAccount> GetCustomerAccount(int accountId)
        {
            var customerAccountResource = new CustomerAccountResource(_apiContext);

            return(await customerAccountResource.GetAccountAsync(accountId));
        }