public ActionResult Create(AddressAttributeModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings)) return AccessDeniedView(); if (ModelState.IsValid) { var addressAttribute = model.ToEntity(); 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.InsertAddressAttribute(addressAttribute); //locales //UpdateAttributeLocales(addressAttribute, model); SuccessNotification(_localizationService.GetResource("Admin.Address.AddressAttributes.Added")); return continueEditing ? RedirectToAction("Edit", new { id = addressAttribute.Id }) : RedirectToAction("List"); } //If we got this far, something failed, redisplay form return View(model); }
protected virtual void UpdateAttributeLocales(AddressAttribute addressAttribute, AddressAttributeModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(addressAttribute, x => x.Name, localized.Name, localized.LanguageId); } }
//create public ActionResult Create() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings)) return AccessDeniedView(); var model = new AddressAttributeModel(); //locales AddLocales(_languageService, model.Locales); return View(model); }
public ActionResult Create(AddressAttributeModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings)) return AccessDeniedView(); if (ModelState.IsValid) { var addressAttribute = model.ToEntity(); _addressAttributeService.InsertAddressAttribute(addressAttribute); //locales UpdateAttributeLocales(addressAttribute, model); SuccessNotification(_localizationService.GetResource("Admin.Address.AddressAttributes.Added")); return continueEditing ? RedirectToAction("Edit", new { id = addressAttribute.Id }) : RedirectToAction("List"); } //If we got this far, something failed, redisplay form return View(model); }
public ActionResult Edit(AddressAttributeModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings)) return AccessDeniedView(); var addressAttribute = _addressAttributeService.GetAddressAttributeById(model.Id); if (addressAttribute == null) //No address attribute found with the specified id return RedirectToAction("List"); if (ModelState.IsValid) { addressAttribute = model.ToEntity(addressAttribute); _addressAttributeService.UpdateAddressAttribute(addressAttribute); //locales UpdateAttributeLocales(addressAttribute, model); SuccessNotification(_localizationService.GetResource("Admin.Address.AddressAttributes.Updated")); if (continueEditing) { //selected tab SaveSelectedTabName(); return RedirectToAction("Edit", new {id = addressAttribute.Id}); } return RedirectToAction("List"); } //If we got this far, something failed, redisplay form 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> /// <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); } }
/// <summary> /// Prepare address attribute model /// </summary> /// <param name="model">Address attribute model</param> /// <param name="addressAttribute">Address attribute</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Address attribute model</returns> public virtual async Task <AddressAttributeModel> PrepareAddressAttributeModelAsync(AddressAttributeModel model, AddressAttribute addressAttribute, bool excludeProperties = false) { Action <AddressAttributeLocalizedModel, int> localizedModelConfiguration = null; if (addressAttribute != null) { //fill in model values from the entity model ??= addressAttribute.ToModel <AddressAttributeModel>(); //prepare nested search model PrepareAddressAttributeValueSearchModel(model.AddressAttributeValueSearchModel, addressAttribute); //define localized model configuration action localizedModelConfiguration = async(locale, languageId) => { locale.Name = await _localizationService.GetLocalizedAsync(addressAttribute, entity => entity.Name, languageId, false, false); }; } //prepare localized models if (!excludeProperties) { model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration); } return(model); }
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.Count > 0) { attributeModel.DefaultValue = enteredText[0]; } } } break; case AttributeControlType.ColorSquares: case AttributeControlType.Datepicker: case AttributeControlType.FileUpload: default: //not supported attribute control types break; } model.CustomAddressAttributes.Add(attributeModel); } }
public static AddressAttribute ToEntity(this AddressAttributeModel model, AddressAttribute destination) { return(model.MapTo(destination)); }
public static AddressAttribute ToEntity(this AddressAttributeModel model) { return(model.MapTo <AddressAttributeModel, AddressAttribute>()); }
public virtual AddressAttribute UpdateAddressAttributeModel(AddressAttributeModel model, AddressAttribute addressAttribute) { addressAttribute = model.ToEntity(addressAttribute); _addressAttributeService.UpdateAddressAttribute(addressAttribute); return(addressAttribute); }
public virtual AddressAttributeModel PrepareAddressAttributeModel() { var model = new AddressAttributeModel(); return(model); }
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.GetTranslation(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.GetTranslation(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); } }
protected virtual async Task UpdateAttributeLocalesAsync(AddressAttribute addressAttribute, AddressAttributeModel model) { foreach (var localized in model.Locales) { await _localizedEntityService.SaveLocalizedValueAsync(addressAttribute, x => x.Name, localized.Name, localized.LanguageId); } }