Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public async Task <CustomerContact> AddCustomerContact(int accountId, CustomerContact contact,
                                                               int tenantId, int?siteId, int?masterCatalogId)
        {
            _apiContext = new ApiContext(tenantId, siteId);

            var customerContactResource = new CustomerContactResource(_apiContext);
            var newContact = await customerContactResource.AddAccountContactAsync(contact, accountId);

            return(newContact);
        }
Ejemplo n.º 3
0
        public async Task <CustomerContact> GetCustomerContact(int tenantId, int?siteId,
                                                               int?masterCatalogId, int accountId, int contactId)
        {
            _apiContext = new ApiContext(tenantId, siteId, masterCatalogId);

            var customerContactResource = new CustomerContactResource(_apiContext);
            var contact = await customerContactResource.GetAccountContactAsync(accountId, contactId);

            return(contact);
        }
Ejemplo n.º 4
0
        public async Task <CustomerContact> UpdateCustomerContact(int tenantId, int?siteId,
                                                                  int?masterCatalogId, CustomerContact contact)
        {
            _apiContext = new ApiContext(tenantId, siteId, masterCatalogId);

            var customerContactResource = new CustomerContactResource(_apiContext);
            var updatedcontact          = await customerContactResource.UpdateAccountContactAsync(contact,
                                                                                                  contact.AccountId, contact.Id);

            return(updatedcontact);
        }
Ejemplo n.º 5
0
        public async Task <IEnumerable <CustomerContact> > GetCustomerContacts(int accountId, int tenantId,
                                                                               int?siteId, int?masterCatalogId, int?startIndex, int?pageSize, string sortBy = null, string filter = null)
        {
            _apiContext = new ApiContext(tenantId, siteId, masterCatalogId);

            var customerContactResource = new CustomerContactResource(_apiContext);
            var contacts = await customerContactResource.GetAccountContactsAsync(accountId, startIndex,
                                                                                 pageSize, sortBy, filter, null);

            return(contacts.Items);
        }
        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);
                }
            }
        }