//edit
        public virtual IActionResult ValueEditPopup(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
            {
                return(AccessDeniedView());
            }

            var cav = _addressAttributeService.GetAddressAttributeValueById(id);

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

            var model = new AddressAttributeValueModel
            {
                AddressAttributeId = cav.AddressAttributeId,
                Name          = cav.Name,
                IsPreSelected = cav.IsPreSelected,
                DisplayOrder  = cav.DisplayOrder
            };

            //locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.Name = cav.GetLocalized(x => x.Name, languageId, false, false);
            });

            return(View(model));
        }
        public virtual AddressAttributeValue InsertAddressAttributeValueModel(AddressAttributeValueModel model)
        {
            var addressAttributeValue = model.ToEntity();

            _addressAttributeService.InsertAddressAttributeValue(addressAttributeValue);
            return(addressAttributeValue);
        }
        public virtual AddressAttributeValueModel PrepareAddressAttributeValueModel(string addressAttributeId)
        {
            var model = new AddressAttributeValueModel();

            model.AddressAttributeId = addressAttributeId;
            return(model);
        }
        /// <summary>
        /// Prepare address attribute value model
        /// </summary>
        /// <param name="model">Address attribute value model</param>
        /// <param name="addressAttribute">Address attribute</param>
        /// <param name="addressAttributeValue">Address attribute value</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Address attribute value model</returns>
        public virtual AddressAttributeValueModel PrepareAddressAttributeValueModel(AddressAttributeValueModel model,
            AddressAttribute addressAttribute, AddressAttributeValue addressAttributeValue, bool excludeProperties = false)
        {
            if (addressAttribute == null)
                throw new ArgumentNullException(nameof(addressAttribute));

            Action<AddressAttributeValueLocalizedModel, int> localizedModelConfiguration = null;

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

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

            model.AddressAttributeId = addressAttribute.Id;

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

            return model;
        }
        public virtual IActionResult ValueEditPopup(AddressAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
            {
                return(AccessDeniedView());
            }

            var cav = _addressAttributeService.GetAddressAttributeValueById(model.Id);

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

            if (ModelState.IsValid)
            {
                cav.Name          = model.Name;
                cav.IsPreSelected = model.IsPreSelected;
                cav.DisplayOrder  = model.DisplayOrder;
                _addressAttributeService.UpdateAddressAttributeValue(cav);

                UpdateValueLocales(cav, model);

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

                ViewBag.RefreshPage = true;
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult ValueEditPopup(string btnId, string formId, AddressAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
            {
                return(AccessDeniedView());
            }

            var cav = _addressAttributeService.GetAddressAttributeValueById(model.Id);

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

            if (ModelState.IsValid)
            {
                cav.Name          = model.Name;
                cav.IsPreSelected = model.IsPreSelected;
                cav.DisplayOrder  = model.DisplayOrder;
                _addressAttributeService.UpdateAddressAttributeValue(cav);

                UpdateValueLocales(cav, model);

                ViewBag.RefreshPage = true;
                ViewBag.btnId       = btnId;
                ViewBag.formId      = formId;
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
 protected  virtual void UpdateValueLocales(AddressAttributeValue addressAttributeValue, AddressAttributeValueModel model)
 {
     foreach (var localized in model.Locales)
     {
         _localizedEntityService.SaveLocalizedValue(addressAttributeValue,
                                                        x => x.Name,
                                                        localized.Name,
                                                        localized.LanguageId);
     }
 }
Exemplo n.º 8
0
        public ActionResult ValueCreatePopup(string btnId, string formId, AddressAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
            {
                return(AccessDeniedView());
            }

            var addressAttribute = _addressAttributeService.GetAddressAttributeById(model.AddressAttributeId);

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

            if (ModelState.IsValid)
            {
                var cav = new AddressAttributeValue
                {
                    Id  = addressAttribute.AddressAttributeValues.Count > 0 ? addressAttribute.AddressAttributeValues.Max(x => x.Id) + 1: 1,
                    _id = ObjectId.GenerateNewId().ToString(),
                    AddressAttributeId = model.AddressAttributeId,
                    Name          = model.Name,
                    IsPreSelected = model.IsPreSelected,
                    DisplayOrder  = model.DisplayOrder
                };

                addressAttribute.Locales.Clear();
                foreach (var local in model.Locales)
                {
                    if (!(String.IsNullOrEmpty(local.Name)))
                    {
                        addressAttribute.Locales.Add(new Core.Domain.Localization.LocalizedProperty()
                        {
                            LanguageId  = local.LanguageId,
                            LocaleKey   = "Name",
                            LocaleValue = local.Name
                        });
                    }
                }

                _addressAttributeService.InsertAddressAttributeValue(cav);
                //UpdateValueLocales(cav, model);

                ViewBag.RefreshPage = true;
                ViewBag.btnId       = btnId;
                ViewBag.formId      = formId;
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 9
0
        public IActionResult ValueDelete(AddressAttributeValueModel model)
        {
            var av  = _addressAttributeService.GetAddressAttributeById(model.AddressAttributeId);
            var cav = av.AddressAttributeValues.FirstOrDefault(x => x.Id == model.Id);

            if (cav == null)
            {
                throw new ArgumentException("No address attribute value found with the specified id");
            }
            _addressAttributeService.DeleteAddressAttributeValue(cav);

            return(new NullJsonResult());
        }
Exemplo n.º 10
0
        public virtual IActionResult ValueEditPopup(AddressAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
            {
                return(AccessDeniedView());
            }

            //try to get an address attribute value with the specified id
            var addressAttributeValue = _addressAttributeService.GetAddressAttributeValueById(model.Id);

            if (addressAttributeValue == null)
            {
                return(RedirectToAction("List"));
            }

            //try to get an address attribute with the specified id
            var addressAttribute = _addressAttributeService.GetAddressAttributeById(addressAttributeValue.AddressAttributeId);

            if (addressAttribute == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                addressAttributeValue.Name          = model.Name;
                addressAttributeValue.IsPreSelected = model.IsPreSelected;
                addressAttributeValue.DisplayOrder  = model.DisplayOrder;
                _addressAttributeService.UpdateAddressAttributeValue(addressAttributeValue);

                UpdateValueLocales(addressAttributeValue, model);

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

                ViewBag.RefreshPage = true;

                return(View(model));
            }

            //prepare model
            model = _addressAttributeModelFactory.PrepareAddressAttributeValueModel(model, addressAttribute, addressAttributeValue, true);

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

            //try to get an address attribute value with the specified id
            var addressAttributeValue = await _addressAttributeService.GetAddressAttributeValueByIdAsync(model.Id);

            if (addressAttributeValue == null)
            {
                return(RedirectToAction("List"));
            }

            //try to get an address attribute with the specified id
            var addressAttribute = await _addressAttributeService.GetAddressAttributeByIdAsync(addressAttributeValue.AddressAttributeId);

            if (addressAttribute == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                addressAttributeValue = model.ToEntity(addressAttributeValue);
                await _addressAttributeService.UpdateAddressAttributeValueAsync(addressAttributeValue);

                await UpdateValueLocalesAsync(addressAttributeValue, model);

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

                ViewBag.RefreshPage = true;

                return(View(model));
            }

            //prepare model
            model = await _addressAttributeModelFactory.PrepareAddressAttributeValueModelAsync(model, addressAttribute, addressAttributeValue, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 12
0
        public IActionResult ValueEditPopup(string btnId, string formId, AddressAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
            {
                return(AccessDeniedView());
            }

            var av  = _addressAttributeService.GetAddressAttributeById(model.AddressAttributeId);
            var cav = av.AddressAttributeValues.FirstOrDefault(x => x.Id == model.Id);

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

            if (ModelState.IsValid)
            {
                cav.Name          = model.Name;
                cav.IsPreSelected = model.IsPreSelected;
                cav.DisplayOrder  = model.DisplayOrder;
                cav.Locales.Clear();
                foreach (var local in model.Locales)
                {
                    cav.Locales.Add(new Core.Domain.Localization.LocalizedProperty()
                    {
                        LanguageId  = local.LanguageId,
                        LocaleKey   = "Name",
                        LocaleValue = local.Name
                    });
                }

                _addressAttributeService.UpdateAddressAttributeValue(cav);

                //UpdateValueLocales(cav, model);

                ViewBag.RefreshPage = true;
                ViewBag.btnId       = btnId;
                ViewBag.formId      = formId;
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 13
0
        public IActionResult ValueDelete(AddressAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
            {
                return(AccessDeniedView());
            }

            var av  = _addressAttributeService.GetAddressAttributeById(model.AddressAttributeId);
            var cav = av.AddressAttributeValues.FirstOrDefault(x => x.Id == model.Id);

            if (cav == null)
            {
                throw new ArgumentException("No address attribute value found with the specified id");
            }
            _addressAttributeService.DeleteAddressAttributeValue(cav);

            return(new NullJsonResult());
        }
Exemplo n.º 14
0
        public IActionResult ValueCreatePopup(AddressAttributeValueModel model)
        {
            var addressAttribute = _addressAttributeService.GetAddressAttributeById(model.AddressAttributeId);

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

            if (ModelState.IsValid)
            {
                _addressAttributeViewModelService.InsertAddressAttributeValueModel(model);
                ViewBag.RefreshPage = true;
                return(View(model));
            }
            //If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 15
0
        public virtual ActionResult ValueCreatePopup(string btnId, string formId, AddressAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
            {
                return(AccessDeniedView());
            }

            var addressAttribute = _addressAttributeService.GetAddressAttributeById(model.AddressAttributeId);

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

            if (ModelState.IsValid)
            {
                var cav = new AddressAttributeValue
                {
                    AddressAttributeId = model.AddressAttributeId,
                    Name            = model.Name,
                    IsPreSelected   = model.IsPreSelected,
                    DisplayOrder    = model.DisplayOrder,
                    PriceAdjustment = model.PriceAdjustment
                };

                _addressAttributeService.InsertAddressAttributeValue(cav);

                //activity log
                _customerActivityService.InsertActivity("AddNewAddressAttributeValue", _localizationService.GetResource("ActivityLog.AddNewAddressAttributeValue"), cav.Id);

                UpdateValueLocales(cav, model);

                ViewBag.RefreshPage = true;
                ViewBag.btnId       = btnId;
                ViewBag.formId      = formId;
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 16
0
        public IActionResult ValueEditPopup(AddressAttributeValueModel model)
        {
            var av  = _addressAttributeService.GetAddressAttributeById(model.AddressAttributeId);
            var cav = av.AddressAttributeValues.FirstOrDefault(x => x.Id == model.Id);

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

            if (ModelState.IsValid)
            {
                _addressAttributeViewModelService.UpdateAddressAttributeValueModel(model, cav);
                ViewBag.RefreshPage = true;
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
        //create
        public ActionResult ValueCreatePopup(int addressAttributeId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
            {
                return(AccessDeniedView());
            }

            var addressAttribute = _addressAttributeService.GetAddressAttributeById(addressAttributeId);

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

            var model = new AddressAttributeValueModel();

            model.AddressAttributeId = addressAttributeId;
            //locales
            AddLocales(_languageService, model.Locales);
            return(View(model));
        }
        /// <summary>
        /// Prepare address attributes
        /// </summary>
        /// <param name="model">Address model</param>
        /// <param name="address">Address entity</param>
        /// <param name="overrideAttributesXml">Overridden address attributes in XML format; pass null to use CustomAttributes of address entity</param>
        protected virtual void PrepareCustomAddressAttributes(AddressModel model,
                                                              Address address, string overrideAttributesXml = "")
        {
            var attributes = _addressAttributeService.GetAllAddressAttributes();

            foreach (var attribute in attributes)
            {
                var attributeModel = new AddressAttributeModel
                {
                    Id         = attribute.Id,
                    Name       = _localizationService.GetLocalized(attribute, x => x.Name),
                    IsRequired = attribute.IsRequired,
                };

                if (attribute.ShouldHaveValues())
                {
                    //values
                    var attributeValues = _addressAttributeService.GetAddressAttributeValues(attribute.Id);
                    foreach (var attributeValue in attributeValues)
                    {
                        var attributeValueModel = new AddressAttributeValueModel
                        {
                            Id            = attributeValue.Id,
                            Name          = _localizationService.GetLocalized(attributeValue, x => x.Name),
                            IsPreSelected = attributeValue.IsPreSelected
                        };
                        attributeModel.Values.Add(attributeValueModel);
                    }
                }

                //set already selected attributes
                var selectedAddressAttributes = !string.IsNullOrEmpty(overrideAttributesXml) ?
                                                overrideAttributesXml :
                                                (address != null ? address.CustomAttributes : null);

                model.CustomAddressAttributes.Add(attributeModel);
            }
        }
        /// <summary>
        /// Prepare address attribute value model
        /// </summary>
        /// <param name="model">Address attribute value model</param>
        /// <param name="addressAttribute">Address attribute</param>
        /// <param name="addressAttributeValue">Address attribute value</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Address attribute value model</returns>
        public virtual AddressAttributeValueModel PrepareAddressAttributeValueModel(AddressAttributeValueModel model,
                                                                                    AddressAttribute addressAttribute, AddressAttributeValue addressAttributeValue, bool excludeProperties = false)
        {
            if (addressAttribute == null)
            {
                throw new ArgumentNullException(nameof(addressAttribute));
            }

            Action <AddressAttributeValueLocalizedModel, int> localizedModelConfiguration = null;

            if (addressAttributeValue != null)
            {
                //fill in model values from the entity
                model = model ?? new AddressAttributeValueModel
                {
                    Name          = addressAttributeValue.Name,
                    IsPreSelected = addressAttributeValue.IsPreSelected,
                    DisplayOrder  = addressAttributeValue.DisplayOrder
                };

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

            model.AddressAttributeId = addressAttribute.Id;

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

            return(model);
        }
 public static AddressAttributeValue ToEntity(this AddressAttributeValueModel model)
 {
     return(model.MapTo <AddressAttributeValueModel, AddressAttributeValue>());
 }
 public static AddressAttributeValue ToEntity(this AddressAttributeValueModel model, AddressAttributeValue destination)
 {
     return(model.MapTo(destination));
 }
        public virtual async Task <AddressAttributeValue> UpdateAddressAttributeValueModel(AddressAttributeValueModel model, AddressAttributeValue addressAttributeValue)
        {
            addressAttributeValue = model.ToEntity(addressAttributeValue);
            await _addressAttributeService.UpdateAddressAttributeValue(addressAttributeValue);

            return(addressAttributeValue);
        }
        public virtual async Task <AddressAttributeValue> InsertAddressAttributeValueModel(AddressAttributeValueModel model)
        {
            var addressAttributeValue = model.ToEntity();
            await _addressAttributeService.InsertAddressAttributeValue(addressAttributeValue);

            return(addressAttributeValue);
        }
        public ActionResult ValueCreatePopup(string btnId, string formId, AddressAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
                return AccessDeniedView();

            var addressAttribute = _addressAttributeService.GetAddressAttributeById(model.AddressAttributeId);
            if (addressAttribute == null)
                //No address attribute found with the specified id
                return RedirectToAction("List");

            if (ModelState.IsValid)
            {
                var cav = new AddressAttributeValue
                {
                    Id = addressAttribute.AddressAttributeValues.Count > 0 ? addressAttribute.AddressAttributeValues.Max(x=>x.Id) + 1: 1,
                    _id = ObjectId.GenerateNewId().ToString(),
                    AddressAttributeId = model.AddressAttributeId,
                    Name = model.Name,
                    IsPreSelected = model.IsPreSelected,
                    DisplayOrder = model.DisplayOrder
                };

                addressAttribute.Locales.Clear();
                foreach (var local in model.Locales)
                {
                    if(!(String.IsNullOrEmpty(local.Name)))
                        addressAttribute.Locales.Add(new Core.Domain.Localization.LocalizedProperty()
                        {
                            LanguageId = local.LanguageId,
                            LocaleKey = "Name",
                            LocaleValue = local.Name
                        });
                }

                _addressAttributeService.InsertAddressAttributeValue(cav);
                //UpdateValueLocales(cav, model);

                ViewBag.RefreshPage = true;
                ViewBag.btnId = btnId;
                ViewBag.formId = formId;
                return View(model);
            }

            //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 UpdateValueLocalesAsync(AddressAttributeValue addressAttributeValue, AddressAttributeValueModel model)
 {
     foreach (var localized in model.Locales)
     {
         await _localizedEntityService.SaveLocalizedValueAsync(addressAttributeValue,
                                                               x => x.Name,
                                                               localized.Name,
                                                               localized.LanguageId);
     }
 }
        public ActionResult ValueEditPopup(string btnId, string formId, AddressAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
                return AccessDeniedView();

            var av = _addressAttributeService.GetAddressAttributeById(model.AddressAttributeId);
            var cav = av.AddressAttributeValues.FirstOrDefault(x => x.Id == model.Id);
            if (cav == null)
                //No address attribute value found with the specified id
                return RedirectToAction("List");

            if (ModelState.IsValid)
            {
                cav.Name = model.Name;
                cav.IsPreSelected = model.IsPreSelected;
                cav.DisplayOrder = model.DisplayOrder;
                cav.Locales.Clear();
                foreach (var local in model.Locales)
                {
                    cav.Locales.Add(new Core.Domain.Localization.LocalizedProperty()
                    {
                        LanguageId = local.LanguageId,
                        LocaleKey = "Name",
                        LocaleValue = local.Name
                    });
                }

                _addressAttributeService.UpdateAddressAttributeValue(cav);

                //UpdateValueLocales(cav, model);

                ViewBag.RefreshPage = true;
                ViewBag.btnId = btnId;
                ViewBag.formId = formId;
                return View(model);
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }
        public ActionResult ValueDelete(AddressAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
                return AccessDeniedView();

            var av = _addressAttributeService.GetAddressAttributeById(model.AddressAttributeId);
            var cav = av.AddressAttributeValues.FirstOrDefault(x => x.Id == model.Id);
            if (cav == null)
                throw new ArgumentException("No address attribute value found with the specified id");
            _addressAttributeService.DeleteAddressAttributeValue(cav);

            return new NullJsonResult();
        }
Exemplo n.º 28
0
        /// <summary>
        /// Prepare address attributes
        /// </summary>
        /// <param name="model">Address model</param>
        /// <param name="address">Address entity</param>
        /// <param name="overrideAttributesXml">Overridden address attributes in XML format; pass null to use CustomAttributes of address entity</param>
        /// <returns>A task that represents the asynchronous operation</returns>
        protected virtual async Task PrepareCustomAddressAttributesAsync(AddressModel model,
                                                                         Address address, string overrideAttributesXml = "")
        {
            var attributes = await _addressAttributeService.GetAllAddressAttributesAsync();

            foreach (var attribute in attributes)
            {
                var attributeModel = new AddressAttributeModel
                {
                    Id                   = attribute.Id,
                    Name                 = await _localizationService.GetLocalizedAsync(attribute, x => x.Name),
                    IsRequired           = attribute.IsRequired,
                    AttributeControlType = attribute.AttributeControlType,
                };

                if (attribute.ShouldHaveValues())
                {
                    //values
                    var attributeValues = await _addressAttributeService.GetAddressAttributeValuesAsync(attribute.Id);

                    foreach (var attributeValue in attributeValues)
                    {
                        var attributeValueModel = new AddressAttributeValueModel
                        {
                            Id            = attributeValue.Id,
                            Name          = await _localizationService.GetLocalizedAsync(attributeValue, x => x.Name),
                            IsPreSelected = attributeValue.IsPreSelected
                        };
                        attributeModel.Values.Add(attributeValueModel);
                    }
                }

                //set already selected attributes
                var selectedAddressAttributes = !string.IsNullOrEmpty(overrideAttributesXml) ?
                                                overrideAttributesXml :
                                                address?.CustomAttributes;
                switch (attribute.AttributeControlType)
                {
                case AttributeControlType.DropdownList:
                case AttributeControlType.RadioList:
                case AttributeControlType.Checkboxes:
                {
                    if (!string.IsNullOrEmpty(selectedAddressAttributes))
                    {
                        //clear default selection
                        foreach (var item in attributeModel.Values)
                        {
                            item.IsPreSelected = false;
                        }

                        //select new values
                        var selectedValues = await _addressAttributeParser.ParseAddressAttributeValuesAsync(selectedAddressAttributes);

                        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(selectedAddressAttributes))
                    {
                        var enteredText = _addressAttributeParser.ParseValues(selectedAddressAttributes, 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;
                }

                model.CustomAddressAttributes.Add(attributeModel);
            }
        }
 public virtual AddressAttributeValue UpdateAddressAttributeValueModel(AddressAttributeValueModel model, AddressAttributeValue addressAttributeValue)
 {
     addressAttributeValue = model.ToEntity(addressAttributeValue);
     _addressAttributeService.UpdateAddressAttributeValue(addressAttributeValue);
     return(addressAttributeValue);
 }
        private async Task PrepareCustomAddressAttributes(AddressModel model, Address address,
                                                          Language language, IList <CustomAttribute> overrideAttributes)
        {
            var attributes = await _addressAttributeService.GetAllAddressAttributes();

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

                if (attribute.ShouldHaveValues())
                {
                    //values
                    var attributeValues = attribute.AddressAttributeValues;
                    foreach (var attributeValue in attributeValues)
                    {
                        var attributeValueModel = new AddressAttributeValueModel {
                            Id            = attributeValue.Id,
                            Name          = attributeValue.GetLocalized(x => x.Name, language.Id),
                            IsPreSelected = attributeValue.IsPreSelected
                        };
                        attributeModel.Values.Add(attributeValueModel);
                    }
                }

                //set already selected attributes
                var selectedAddressAttributes = overrideAttributes ?? (address?.Attributes);

                switch (attribute.AttributeControlType)
                {
                case AttributeControlType.DropdownList:
                case AttributeControlType.RadioList:
                case AttributeControlType.Checkboxes:
                {
                    if (selectedAddressAttributes != null)
                    {
                        //clear default selection
                        foreach (var item in attributeModel.Values)
                        {
                            item.IsPreSelected = false;
                        }

                        //select new values
                        var selectedValues = await _addressAttributeParser.ParseAddressAttributeValues(selectedAddressAttributes);

                        foreach (var attributeValue in selectedValues)
                        {
                            if (attributeModel.Id == attributeValue.AddressAttributeId)
                            {
                                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 (selectedAddressAttributes != null)
                    {
                        var enteredText = selectedAddressAttributes.Where(x => x.Key == attribute.Id).Select(x => x.Value).ToList();
                        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;
                }

                model.CustomAddressAttributes.Add(attributeModel);
            }
        }
        /// <summary>
        /// Prepare address attribute value model
        /// </summary>
        /// <param name="model">Address attribute value model</param>
        /// <param name="addressAttribute">Address attribute</param>
        /// <param name="addressAttributeValue">Address attribute value</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the address attribute value model
        /// </returns>
        public virtual async Task <AddressAttributeValueModel> PrepareAddressAttributeValueModelAsync(AddressAttributeValueModel model,
                                                                                                      AddressAttribute addressAttribute, AddressAttributeValue addressAttributeValue, bool excludeProperties = false)
        {
            if (addressAttribute == null)
            {
                throw new ArgumentNullException(nameof(addressAttribute));
            }

            Func <AddressAttributeValueLocalizedModel, int, Task> localizedModelConfiguration = null;

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

                //define localized model configuration action
                localizedModelConfiguration = async(locale, languageId) =>
                {
                    locale.Name = await _localizationService.GetLocalizedAsync(addressAttributeValue, entity => entity.Name, languageId, false, false);
                };
            }

            model.AddressAttributeId = addressAttribute.Id;

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

            return(model);
        }
Exemplo n.º 32
0
        private static void PrepareCustomAddressAttributes(this AddressModel model,
                                                           Address address,
                                                           IAddressAttributeService addressAttributeService,
                                                           IAddressAttributeParser addressAttributeParser,
                                                           string overrideAttributesXml = "")
        {
            if (addressAttributeService == null)
            {
                throw new ArgumentNullException("addressAttributeService");
            }

            if (addressAttributeParser == null)
            {
                throw new ArgumentNullException("addressAttributeParser");
            }

            var attributes = addressAttributeService.GetAllAddressAttributes();

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

                if (attribute.ShouldHaveValues())
                {
                    //values
                    var attributeValues = addressAttributeService.GetAddressAttributeValues(attribute.Id);
                    foreach (var attributeValue in attributeValues)
                    {
                        var attributeValueModel = new AddressAttributeValueModel
                        {
                            Id            = attributeValue.Id,
                            Name          = attributeValue.GetLocalized(x => x.Name),
                            IsPreSelected = attributeValue.IsPreSelected
                        };
                        attributeModel.Values.Add(attributeValueModel);
                    }
                }

                //set already selected attributes
                var selectedAddressAttributes = !String.IsNullOrEmpty(overrideAttributesXml) ?
                                                overrideAttributesXml :
                                                (address != null ? address.CustomAttributes : null);
                switch (attribute.AttributeControlType)
                {
                case AttributeControlType.DropdownList:
                case AttributeControlType.RadioList:
                case AttributeControlType.Checkboxes:
                {
                    if (!String.IsNullOrEmpty(selectedAddressAttributes))
                    {
                        //clear default selection
                        foreach (var item in attributeModel.Values)
                        {
                            item.IsPreSelected = false;
                        }

                        //select new values
                        var selectedValues = addressAttributeParser.ParseAddressAttributeValues(selectedAddressAttributes);
                        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(selectedAddressAttributes))
                    {
                        var enteredText = addressAttributeParser.ParseValues(selectedAddressAttributes, 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;
                }

                model.CustomAddressAttributes.Add(attributeModel);
            }
        }
        public ActionResult ValueEditPopup(string btnId, string formId, AddressAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
                return AccessDeniedView();

            var cav = _addressAttributeService.GetAddressAttributeValueById(model.Id);
            if (cav == null)
                //No address attribute value found with the specified id
                return RedirectToAction("List");

            if (ModelState.IsValid)
            {
                cav.Name = model.Name;
                cav.IsPreSelected = model.IsPreSelected;
                cav.DisplayOrder = model.DisplayOrder;
                _addressAttributeService.UpdateAddressAttributeValue(cav);

                UpdateValueLocales(cav, model);

                ViewBag.RefreshPage = true;
                ViewBag.btnId = btnId;
                ViewBag.formId = formId;
                return View(model);
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }
        //edit
        public ActionResult ValueEditPopup(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
                return AccessDeniedView();

            var cav = _addressAttributeService.GetAddressAttributeValueById(id);
            if (cav == null)
                //No address attribute value found with the specified id
                return RedirectToAction("List");

            var model = new AddressAttributeValueModel
            {
                AddressAttributeId = cav.AddressAttributeId,
                Name = cav.Name,
                IsPreSelected = cav.IsPreSelected,
                DisplayOrder = cav.DisplayOrder
            };

            //locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.Name = cav.GetLocalized(x => x.Name, languageId, false, false);
            });

            return View(model);
        }
Exemplo n.º 35
0
 protected virtual void UpdateValueLocales(AddressAttributeValue addressAttributeValue, AddressAttributeValueModel model)
 {
     foreach (var localized in model.Locales)
     {
         _localizedEntityService.SaveLocalizedValue(addressAttributeValue,
                                                    x => x.Name,
                                                    localized.Name,
                                                    localized.LanguageId);
     }
 }
        //create
        public ActionResult ValueCreatePopup(int addressAttributeId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
                return AccessDeniedView();

            var addressAttribute = _addressAttributeService.GetAddressAttributeById(addressAttributeId);
            if (addressAttribute == null)
                //No address attribute found with the specified id
                return RedirectToAction("List");

            var model = new AddressAttributeValueModel();
            model.AddressAttributeId = addressAttributeId;
            //locales
            AddLocales(_languageService, model.Locales);
            return View(model);
        }