public virtual async Task <IActionResult> Edit(VendorModel model, bool continueEditing, IFormCollection form)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageVendors))
            {
                return(AccessDeniedView());
            }

            //try to get a vendor with the specified id
            var vendor = await _vendorService.GetVendorByIdAsync(model.Id);

            if (vendor == null || vendor.Deleted)
            {
                return(RedirectToAction("List"));
            }

            //parse vendor attributes
            var vendorAttributesXml = await ParseVendorAttributesAsync(form);

            (await _vendorAttributeParser.GetAttributeWarningsAsync(vendorAttributesXml)).ToList()
            .ForEach(warning => ModelState.AddModelError(string.Empty, warning));

            //custom address attributes
            var customAttributes = await _addressAttributeParser.ParseCustomAddressAttributesAsync(form);

            var customAttributeWarnings = await _addressAttributeParser.GetAttributeWarningsAsync(customAttributes);

            foreach (var error in customAttributeWarnings)
            {
                ModelState.AddModelError(string.Empty, error);
            }

            if (ModelState.IsValid)
            {
                var prevPictureId = vendor.PictureId;
                vendor = model.ToEntity(vendor);
                await _vendorService.UpdateVendorAsync(vendor);

                //vendor attributes
                await _genericAttributeService.SaveAttributeAsync(vendor, NopVendorDefaults.VendorAttributes, vendorAttributesXml);

                //activity log
                await _customerActivityService.InsertActivityAsync("EditVendor",
                                                                   string.Format(await _localizationService.GetResourceAsync("ActivityLog.EditVendor"), vendor.Id), vendor);

                //search engine name
                model.SeName = await _urlRecordService.ValidateSeNameAsync(vendor, model.SeName, vendor.Name, true);

                await _urlRecordService.SaveSlugAsync(vendor, model.SeName, 0);

                //address
                var address = await _addressService.GetAddressByIdAsync(vendor.AddressId);

                if (address == null)
                {
                    address = model.Address.ToEntity <Address>();
                    address.CustomAttributes = customAttributes;
                    address.CreatedOnUtc     = DateTime.UtcNow;

                    //some validation
                    if (address.CountryId == 0)
                    {
                        address.CountryId = null;
                    }
                    if (address.StateProvinceId == 0)
                    {
                        address.StateProvinceId = null;
                    }

                    await _addressService.InsertAddressAsync(address);

                    vendor.AddressId = address.Id;
                    await _vendorService.UpdateVendorAsync(vendor);
                }
                else
                {
                    address = model.Address.ToEntity(address);
                    address.CustomAttributes = customAttributes;

                    //some validation
                    if (address.CountryId == 0)
                    {
                        address.CountryId = null;
                    }
                    if (address.StateProvinceId == 0)
                    {
                        address.StateProvinceId = null;
                    }

                    await _addressService.UpdateAddressAsync(address);
                }

                //locales
                await UpdateLocalesAsync(vendor, model);

                //delete an old picture (if deleted or updated)
                if (prevPictureId > 0 && prevPictureId != vendor.PictureId)
                {
                    var prevPicture = await _pictureService.GetPictureByIdAsync(prevPictureId);

                    if (prevPicture != null)
                    {
                        await _pictureService.DeletePictureAsync(prevPicture);
                    }
                }
                //update picture seo file name
                await UpdatePictureSeoNamesAsync(vendor);

                _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Vendors.Updated"));

                if (!continueEditing)
                {
                    return(RedirectToAction("List"));
                }

                return(RedirectToAction("Edit", new { id = vendor.Id }));
            }

            //prepare model
            model = await _vendorModelFactory.PrepareVendorModelAsync(model, vendor, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
        public virtual async Task <IActionResult> AddressCreate(CustomerAddressModel model, IFormCollection form)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCustomers))
            {
                return(AccessDeniedView());
            }

            var companyId = model.CustomerId;
            //try to get a customer with the specified id
            var companies = await _companyService.GetCompanyCustomersByCompanyIdAsync(model.CustomerId);

            if (!companies.Any())
            {
                return(RedirectToAction("List"));
            }

            //custom address attributes
            var customAttributes = await _addressAttributeParser.ParseCustomAddressAttributesAsync(form);

            var customAttributeWarnings = await _addressAttributeParser.GetAttributeWarningsAsync(customAttributes);

            foreach (var error in customAttributeWarnings)
            {
                ModelState.AddModelError(string.Empty, error);
            }

            if (ModelState.IsValid)
            {
                var address = model.Address.ToEntity <Address>();
                address.CustomAttributes = customAttributes;
                address.CreatedOnUtc     = DateTime.UtcNow;

                //some validation
                if (address.CountryId == 0)
                {
                    address.CountryId = null;
                }
                if (address.StateProvinceId == 0)
                {
                    address.StateProvinceId = null;
                }

                await _addressService.InsertAddressAsync(address);

                foreach (var company in companies)
                {
                    var customer = await _customerService.GetCustomerByIdAsync(company.CustomerId);

                    await _customerService.InsertCustomerAddressAsync(customer, address);

                    customer.ShippingAddressId = address.Id;
                    customer.BillingAddressId  = address.Id;
                    await _customerService.UpdateCustomerAsync(customer);
                }
                _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Companies.Company.Addresses.Added"));
                return(RedirectToAction("Edit", new { id = companyId }));
            }

            //if we got this far, something failed, redisplay form
            return(View(model));
        }