public virtual async Task<IActionResult> Create(CustomerAttributeModel model, bool continueEditing)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageSettings))
                return AccessDeniedView();

            if (ModelState.IsValid)
            {
                var customerAttribute = model.ToEntity<CustomerAttribute>();
                await _customerAttributeService.InsertCustomerAttributeAsync(customerAttribute);

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

                //locales
                await UpdateAttributeLocalesAsync(customerAttribute, model);

                _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Customers.CustomerAttributes.Added"));

                if (!continueEditing)
                    return RedirectToAction("List");
                
                return RedirectToAction("Edit", new { id = customerAttribute.Id });
            }
            
            //prepare model
            model = await _customerAttributeModelFactory.PrepareCustomerAttributeModelAsync(model, null, true);

            //if we got this far, something failed, redisplay form
            return View(model);
        }
Exemple #2
0
        public async Task SetUp()
        {
            _customerModelFactory = GetService <ICustomerModelFactory>();
            _customer             = await GetService <IWorkContext>().GetCurrentCustomerAsync();

            _customerAttributeService = GetService <ICustomerAttributeService>();

            _customerAttributes = new[]
            {
                new CustomerAttribute
                {
                    AttributeControlType = AttributeControlType.Checkboxes, Name = "Test customer attribute 1"
                },
                new CustomerAttribute
                {
                    AttributeControlType = AttributeControlType.ColorSquares, Name = "Test customer attribute 2"
                },
                new CustomerAttribute
                {
                    AttributeControlType = AttributeControlType.Datepicker, Name = "Test customer attribute 3"
                },
                new CustomerAttribute
                {
                    AttributeControlType = AttributeControlType.DropdownList, Name = "Test customer attribute 4"
                },
                new CustomerAttribute
                {
                    AttributeControlType = AttributeControlType.FileUpload, Name = "Test customer attribute 5"
                },
                new CustomerAttribute
                {
                    AttributeControlType = AttributeControlType.ImageSquares, Name = "Test customer attribute 6"
                },
                new CustomerAttribute
                {
                    AttributeControlType = AttributeControlType.MultilineTextbox, Name = "Test customer attribute 7"
                },
                new CustomerAttribute
                {
                    AttributeControlType = AttributeControlType.RadioList, Name = "Test customer attribute 8"
                },
                new CustomerAttribute
                {
                    AttributeControlType = AttributeControlType.ReadonlyCheckboxes, Name = "Test customer attribute 9"
                },
                new CustomerAttribute
                {
                    AttributeControlType = AttributeControlType.TextBox, Name = "Test customer attribute 10"
                }
            };

            foreach (var customerAttribute in _customerAttributes)
            {
                await _customerAttributeService.InsertCustomerAttributeAsync(customerAttribute);
            }
        }