public ActionResult Create(CustomerAttributeModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var customerAttribute = model.ToEntity();
                _customerAttributeService.InsertCustomerAttribute(customerAttribute);
                //locales
                UpdateAttributeLocales(customerAttribute, model);

                SuccessNotification(_localizationService.GetResource("Admin.Customers.CustomerAttributes.Added"));

                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabName();

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

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
        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);
        }
Beispiel #3
0
        public async Task <IActionResult> Edit(CustomerAttributeModel model, bool continueEditing)
        {
            var customerAttribute = await _customerAttributeService.GetCustomerAttributeById(model.Id);

            if (customerAttribute == null)
            {
                //No customer attribute found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                customerAttribute = await _customerAttributeViewModelService.UpdateCustomerAttributeModel(model, customerAttribute);

                SuccessNotification(_localizationService.GetResource("Admin.Customers.CustomerAttributes.Updated"));
                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabIndex();

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

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
Beispiel #4
0
        public virtual async Task <CustomerAttribute> InsertCustomerAttributeModel(CustomerAttributeModel model)
        {
            var customerAttribute = model.ToEntity();
            await _customerAttributeService.InsertCustomerAttribute(customerAttribute);

            return(customerAttribute);
        }
        public virtual CustomerAttribute InsertCustomerAttributeModel(CustomerAttributeModel model)
        {
            var customerAttribute = model.ToEntity();

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

            var customerAttribute = await _customerAttributeService.GetCustomerAttributeByIdAsync(model.Id);
            if (customerAttribute == null)
                //no customer attribute found with the specified id
                return RedirectToAction("List");

            if (!ModelState.IsValid)
                //if we got this far, something failed, redisplay form
                return View(model);

            customerAttribute = model.ToEntity(customerAttribute);
            await _customerAttributeService.UpdateCustomerAttributeAsync(customerAttribute);

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

            //locales
            await UpdateAttributeLocalesAsync(customerAttribute, model);

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

            if (!continueEditing)
                return RedirectToAction("List");
            
            return RedirectToAction("Edit", new { id = customerAttribute.Id });
        }
Beispiel #7
0
        public virtual async Task <CustomerAttribute> UpdateCustomerAttributeModel(CustomerAttributeModel model, CustomerAttribute customerAttribute)
        {
            customerAttribute = model.ToEntity(customerAttribute);
            await _customerAttributeService.UpdateCustomerAttribute(customerAttribute);

            return(customerAttribute);
        }
Beispiel #8
0
        /// <summary>
        /// Prepare customer attribute model
        /// </summary>
        /// <param name="model">Customer attribute model</param>
        /// <param name="customerAttribute">Customer attribute</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Customer attribute model</returns>
        public virtual CustomerAttributeModel PrepareCustomerAttributeModel(CustomerAttributeModel model,
                                                                            CustomerAttribute customerAttribute, bool excludeProperties = false)
        {
            Action <CustomerAttributeLocalizedModel, int> localizedModelConfiguration = null;

            if (customerAttribute != null)
            {
                //fill in model values from the entity
                model = model ?? customerAttribute.ToModel <CustomerAttributeModel>();

                //prepare nested search model
                PrepareCustomerAttributeValueSearchModel(model.CustomerAttributeValueSearchModel, customerAttribute);

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name = _localizationService.GetLocalized(customerAttribute, entity => entity.Name, languageId, false, false);
                };
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            return(model);
        }
Beispiel #9
0
        public ActionResult Edit(CustomerAttributeModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
            {
                return(AccessDeniedView());
            }

            var customerAttribute = _customerAttributeService.GetCustomerAttributeById(model.Id);

            if (customerAttribute == null)
            {
                //No customer attribute found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                customerAttribute         = model.ToEntity(customerAttribute);
                customerAttribute.Locales = UpdateAttributeLocales(customerAttribute, model);
                _customerAttributeService.UpdateCustomerAttribute(customerAttribute);

                SuccessNotification(_localizationService.GetResource("Admin.Customers.CustomerAttributes.Updated"));
                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabIndex();

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

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
 protected virtual void UpdateAttributeLocales(CustomerAttribute customerAttribute, CustomerAttributeModel model)
 {
     foreach (var localized in model.Locales)
     {
         _localizedEntityService.SaveLocalizedValue(customerAttribute,
                                                        x => x.Name,
                                                        localized.Name,
                                                        localized.LanguageId);
     }
 }
        //create
        public ActionResult Create()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
                return AccessDeniedView();

            var model = new CustomerAttributeModel();
            //locales
            AddLocales(_languageService, model.Locales);
            return View(model);
        }
 protected void UpdateAttributeLocales(CustomerAttribute customerAttribute, CustomerAttributeModel model)
 {
     foreach (var localized in model.Locales)
     {
         _localizedEntityService.SaveLocalizedValue(customerAttribute,
                                                    x => x.Name,
                                                    localized.Name,
                                                    localized.LanguageId);
     }
 }
 public IActionResult Create(CustomerAttributeModel model, bool continueEditing)
 {
     if (ModelState.IsValid)
     {
         var customerAttribute = _customerAttributeViewModelService.InsertCustomerAttributeModel(model);
         SuccessNotification(_localizationService.GetResource("Admin.Customers.CustomerAttributes.Added"));
         return(continueEditing ? RedirectToAction("Edit", new { id = customerAttribute.Id }) : RedirectToAction("List"));
     }
     //If we got this far, something failed, redisplay form
     return(View(model));
 }
        public virtual async Task <CustomerAttribute> UpdateCustomerAttributeModel(CustomerAttributeModel model, CustomerAttribute customerAttribute)
        {
            customerAttribute = model.ToEntity(customerAttribute);
            if (customerAttribute.IsReadOnly && customerAttribute.IsRequired)
            {
                customerAttribute.IsRequired = false;
            }

            await _customerAttributeService.UpdateCustomerAttribute(customerAttribute);

            return(customerAttribute);
        }
        public virtual async Task <CustomerAttribute> InsertCustomerAttributeModel(CustomerAttributeModel model)
        {
            var customerAttribute = model.ToEntity();

            if (customerAttribute.IsReadOnly && customerAttribute.IsRequired)
            {
                customerAttribute.IsRequired = false;
            }

            await _customerAttributeService.InsertCustomerAttribute(customerAttribute);

            return(customerAttribute);
        }
        //create
        public ActionResult Create()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
            {
                return(AccessDeniedView());
            }

            var model = new CustomerAttributeModel();

            //locales
            AddLocales(_languageService, model.Locales);
            return(View(model));
        }
        public ActionResult Create(CustomerAttributeModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
                return AccessDeniedView();

            if (ModelState.IsValid)
            {
                var customerAttribute = model.ToEntity();
                customerAttribute.Locales = UpdateAttributeLocales(customerAttribute, model);
                _customerAttributeService.InsertCustomerAttribute(customerAttribute);

                SuccessNotification(_localizationService.GetResource("Admin.Customers.CustomerAttributes.Added"));
                return continueEditing ? RedirectToAction("Edit", new { id = customerAttribute.Id }) : RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }
        public virtual IActionResult Edit(CustomerAttributeModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
            {
                return(AccessDeniedView());
            }

            var customerAttribute = _customerAttributeService.GetCustomerAttributeById(model.Id);

            if (customerAttribute == null)
            {
                //no customer attribute found with the specified id
                return(RedirectToAction("List"));
            }

            if (!ModelState.IsValid)
            {
                //if we got this far, something failed, redisplay form
                return(View(model));
            }

            customerAttribute = model.ToEntity(customerAttribute);
            _customerAttributeService.UpdateCustomerAttribute(customerAttribute);

            //activity log
            _customerActivityService.InsertActivity("EditCustomerAttribute",
                                                    string.Format(_localizationService.GetResource("ActivityLog.EditCustomerAttribute"), customerAttribute.Id),
                                                    customerAttribute);

            //locales
            UpdateAttributeLocales(customerAttribute, model);

            SuccessNotification(_localizationService.GetResource("Admin.Customers.CustomerAttributes.Updated"));

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

            //selected tab
            SaveSelectedTabName();

            return(RedirectToAction("Edit", new { id = customerAttribute.Id }));
        }
        public virtual IActionResult Create(CustomerAttributeModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
            {
                return(AccessDeniedView());
            }

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

                //activity log
                _customerActivityService.InsertActivity("AddNewCustomerAttribute",
                                                        string.Format(_localizationService.GetResource("ActivityLog.AddNewCustomerAttribute"), customerAttribute.Id),
                                                        customerAttribute);

                //locales
                UpdateAttributeLocales(customerAttribute, model);

                SuccessNotification(_localizationService.GetResource("Admin.Customers.CustomerAttributes.Added"));

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

                //selected tab
                SaveSelectedTabName();

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

            //prepare model
            model = _customerAttributeModelFactory.PrepareCustomerAttributeModel(model, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
 protected virtual List<LocalizedProperty> UpdateAttributeLocales(CustomerAttribute customerAttribute, CustomerAttributeModel model)
 {
     List<LocalizedProperty> localized = new List<LocalizedProperty>();
     foreach (var local in model.Locales)
     {
         if (!(String.IsNullOrEmpty(local.Name)))
             localized.Add(new LocalizedProperty()
             {
                 LanguageId = local.LanguageId,
                 LocaleKey = "Name",
                 LocaleValue = local.Name
             });
     }
     return localized;
 }
Beispiel #21
0
        public virtual CustomerAttributeModel PrepareCustomerAttributeModel()
        {
            var model = new CustomerAttributeModel();

            return(model);
        }
 public static CustomerAttribute ToEntity(this CustomerAttributeModel model)
 {
     return(Mapper.Map <CustomerAttributeModel, CustomerAttribute>(model));
 }
        public ActionResult Edit(CustomerAttributeModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
                return AccessDeniedView();

            var customerAttribute = _customerAttributeService.GetCustomerAttributeById(model.Id);
            if (customerAttribute == null)
                //No customer attribute found with the specified id
                return RedirectToAction("List");

            if (ModelState.IsValid)
            {
                customerAttribute = model.ToEntity(customerAttribute);
                _customerAttributeService.UpdateCustomerAttribute(customerAttribute);
                //locales
                UpdateAttributeLocales(customerAttribute, model);

                SuccessNotification(_localizationService.GetResource("Admin.Customers.CustomerAttributes.Updated"));
                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabName();

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

            //If we got this far, something failed, redisplay form
            return View(model);
        }
 /// <returns>A task that represents the asynchronous operation</returns>
 protected virtual async Task UpdateAttributeLocalesAsync(CustomerAttribute customerAttribute, CustomerAttributeModel model)
 {
     foreach (var localized in model.Locales)
     {
         await _localizedEntityService.SaveLocalizedValueAsync(customerAttribute,
                                                               x => x.Name,
                                                               localized.Name,
                                                               localized.LanguageId);
     }
 }
 public virtual CustomerAttribute UpdateCustomerAttributeModel(CustomerAttributeModel model, CustomerAttribute customerAttribute)
 {
     customerAttribute = model.ToEntity(customerAttribute);
     _customerAttributeService.UpdateCustomerAttribute(customerAttribute);
     return(customerAttribute);
 }
 public static CustomerAttribute ToEntity(this CustomerAttributeModel model, CustomerAttribute destination)
 {
     return(model.MapTo(destination));
 }
 public static CustomerAttribute ToEntity(this CustomerAttributeModel model)
 {
     return(model.MapTo <CustomerAttributeModel, CustomerAttribute>());
 }
        public virtual IList <CustomerAttributeModel> PrepareCustomCustomerAttributes(Customer customer, string overrideAttributesXml = "")
        {
            if (customer == null)
            {
                throw new ArgumentNullException("customer");
            }

            var result = new List <CustomerAttributeModel>();

            var customerAttributes = _customerAttributeService.GetAllCustomerAttributes();

            foreach (var attribute in customerAttributes)
            {
                var attributeModel = new CustomerAttributeModel
                {
                    Id                   = attribute.Id,
                    Name                 = attribute.GetLocalized(x => x.Name),
                    IsRequired           = attribute.IsRequired,
                    AttributeControlType = attribute.AttributeControlType,
                };

                if (attribute.ShouldHaveValues())
                {
                    //values
                    var attributeValues = _customerAttributeService.GetCustomerAttributeValues(attribute.Id);
                    foreach (var attributeValue in attributeValues)
                    {
                        var valueModel = new CustomerAttributeValueModel
                        {
                            Id            = attributeValue.Id,
                            Name          = attributeValue.GetLocalized(x => x.Name),
                            IsPreSelected = attributeValue.IsPreSelected
                        };
                        attributeModel.Values.Add(valueModel);
                    }
                }

                //set already selected attributes
                var selectedAttributesXml = !String.IsNullOrEmpty(overrideAttributesXml) ?
                                            overrideAttributesXml :
                                            customer.GetAttribute <string>(SystemCustomerAttributeNames.CustomCustomerAttributes, _genericAttributeService);
                switch (attribute.AttributeControlType)
                {
                case AttributeControlType.DropdownList:
                case AttributeControlType.RadioList:
                case AttributeControlType.Checkboxes:
                {
                    if (!String.IsNullOrEmpty(selectedAttributesXml))
                    {
                        //clear default selection
                        foreach (var item in attributeModel.Values)
                        {
                            item.IsPreSelected = false;
                        }

                        //select new values
                        var selectedValues = _customerAttributeParser.ParseCustomerAttributeValues(selectedAttributesXml);
                        foreach (var attributeValue in selectedValues)
                        {
                            foreach (var item in attributeModel.Values)
                            {
                                if (attributeValue.Id == item.Id)
                                {
                                    item.IsPreSelected = true;
                                }
                            }
                        }
                    }
                }
                break;

                case AttributeControlType.ReadonlyCheckboxes:
                {
                    //do nothing
                    //values are already pre-set
                }
                break;

                case AttributeControlType.TextBox:
                case AttributeControlType.MultilineTextbox:
                {
                    if (!String.IsNullOrEmpty(selectedAttributesXml))
                    {
                        var enteredText = _customerAttributeParser.ParseValues(selectedAttributesXml, attribute.Id);
                        if (enteredText.Any())
                        {
                            attributeModel.DefaultValue = enteredText[0];
                        }
                    }
                }
                break;

                case AttributeControlType.ColorSquares:
                case AttributeControlType.ImageSquares:
                case AttributeControlType.Datepicker:
                case AttributeControlType.FileUpload:
                default:
                    //not supported attribute control types
                    break;
                }

                result.Add(attributeModel);
            }


            return(result);
        }
Beispiel #29
0
        protected virtual List <LocalizedProperty> UpdateAttributeLocales(CustomerAttribute customerAttribute, CustomerAttributeModel model)
        {
            List <LocalizedProperty> localized = new List <LocalizedProperty>();

            foreach (var local in model.Locales)
            {
                if (!(String.IsNullOrEmpty(local.Name)))
                {
                    localized.Add(new LocalizedProperty()
                    {
                        LanguageId  = local.LanguageId,
                        LocaleKey   = "Name",
                        LocaleValue = local.Name
                    });
                }
            }
            return(localized);
        }