public virtual IActionResult ValueCreatePopup(VendorAttributeValueModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings)) return AccessDeniedView(); //try to get a vendor attribute with the specified id var vendorAttribute = _vendorAttributeService.GetVendorAttributeById(model.VendorAttributeId); if (vendorAttribute == null) return RedirectToAction("List"); if (ModelState.IsValid) { var value = model.ToEntity<VendorAttributeValue>(); _vendorAttributeService.InsertVendorAttributeValue(value); //activity log _customerActivityService.InsertActivity("AddNewVendorAttributeValue", string.Format(_localizationService.GetResource("ActivityLog.AddNewVendorAttributeValue"), value.Id), value); UpdateValueLocales(value, model); ViewBag.RefreshPage = true; return View(model); } //prepare model model = _vendorAttributeModelFactory.PrepareVendorAttributeValueModel(model, vendorAttribute, null, true); //if we got this far, something failed, redisplay form return View(model); }
/// <summary> /// Prepare vendor attribute value model /// </summary> /// <param name="model">Vendor attribute value model</param> /// <param name="vendorAttribute">Vendor attribute</param> /// <param name="vendorAttributeValue">Vendor attribute value</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Vendor attribute value model</returns> public virtual VendorAttributeValueModel PrepareVendorAttributeValueModel(VendorAttributeValueModel model, VendorAttribute vendorAttribute, VendorAttributeValue vendorAttributeValue, bool excludeProperties = false) { if (vendorAttribute == null) { throw new ArgumentNullException(nameof(vendorAttribute)); } Action <VendorAttributeValueLocalizedModel, int> localizedModelConfiguration = null; if (vendorAttributeValue != null) { //fill in model values from the entity model = model ?? vendorAttributeValue.ToModel <VendorAttributeValueModel>(); //define localized model configuration action localizedModelConfiguration = (locale, languageId) => { locale.Name = _localizationService.GetLocalized(vendorAttributeValue, entity => entity.Name, languageId, false, false); }; } model.VendorAttributeId = vendorAttribute.Id; //prepare localized models if (!excludeProperties) { model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration); } return(model); }
public virtual IActionResult ValueEditPopup(VendorAttributeValueModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings)) { return(AccessDeniedView()); } var value = _vendorAttributeService.GetVendorAttributeValueById(model.Id); if (value == null) { //No vendor attribute value found with the specified id return(RedirectToAction("List")); } if (ModelState.IsValid) { value.Name = model.Name; value.IsPreSelected = model.IsPreSelected; value.DisplayOrder = model.DisplayOrder; _vendorAttributeService.UpdateVendorAttributeValue(value); //activity log _customerActivityService.InsertActivity("EditVendorAttributeValue", string.Format(_localizationService.GetResource("ActivityLog.EditVendorAttributeValue"), value.Id), value); UpdateValueLocales(value, model); ViewBag.RefreshPage = true; return(View(model)); } //If we got this far, something failed, redisplay form return(View(model)); }
//edit public virtual IActionResult ValueEditPopup(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings)) { return(AccessDeniedView()); } var cav = _vendorAttributeService.GetVendorAttributeValueById(id); if (cav == null) { //No vendor attribute value found with the specified id return(RedirectToAction("List")); } var model = new VendorAttributeValueModel { VendorAttributeId = cav.VendorAttributeId, 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)); }
/// <returns>A task that represents the asynchronous operation</returns> public virtual async Task <IActionResult> ValueEditPopup(VendorAttributeValueModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageSettings)) { return(AccessDeniedView()); } //try to get a vendor attribute value with the specified id var vendorAttributeValue = await _vendorAttributeService.GetVendorAttributeValueByIdAsync(model.Id); if (vendorAttributeValue == null) { return(RedirectToAction("List")); } //try to get a vendor attribute with the specified id var vendorAttribute = await _vendorAttributeService.GetVendorAttributeByIdAsync(vendorAttributeValue.VendorAttributeId); if (vendorAttribute == null) { return(RedirectToAction("List")); } if (ModelState.IsValid) { vendorAttributeValue = model.ToEntity(vendorAttributeValue); await _vendorAttributeService.UpdateVendorAttributeValueAsync(vendorAttributeValue); //activity log await _customerActivityService.InsertActivityAsync("EditVendorAttributeValue", string.Format(await _localizationService.GetResourceAsync("ActivityLog.EditVendorAttributeValue"), vendorAttributeValue.Id), vendorAttributeValue); await UpdateValueLocalesAsync(vendorAttributeValue, model); ViewBag.RefreshPage = true; return(View(model)); } //prepare model model = await _vendorAttributeModelFactory.PrepareVendorAttributeValueModelAsync(model, vendorAttribute, vendorAttributeValue, true); //if we got this far, something failed, redisplay form return(View(model)); }
//create public virtual IActionResult ValueCreatePopup(int vendorAttributeId) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings)) { return(AccessDeniedView()); } var vendorAttribute = _vendorAttributeService.GetVendorAttributeById(vendorAttributeId); if (vendorAttribute == null) { //No vendor attribute found with the specified id return(RedirectToAction("List")); } var model = new VendorAttributeValueModel { VendorAttributeId = vendorAttributeId }; //locales AddLocales(_languageService, model.Locales); return(View(model)); }
/// <summary> /// Prepare vendor attribute models /// </summary> /// <param name="vendorAttributesXml">Vendor attributes in XML format</param> /// <returns>List of the vendor attribute model</returns> protected virtual IList <VendorAttributeModel> PrepareVendorAttributes(string vendorAttributesXml) { var result = new List <VendorAttributeModel>(); var vendorAttributes = _vendorAttributeService.GetAllVendorAttributes(); foreach (var attribute in vendorAttributes) { var attributeModel = new VendorAttributeModel { Id = attribute.Id, Name = _localizationService.GetLocalized(attribute, x => x.Name), IsRequired = attribute.IsRequired, AttributeControlType = attribute.AttributeControlType, }; if (attribute.ShouldHaveValues()) { //values var attributeValues = _vendorAttributeService.GetVendorAttributeValues(attribute.Id); foreach (var attributeValue in attributeValues) { var valueModel = new VendorAttributeValueModel { Id = attributeValue.Id, Name = _localizationService.GetLocalized(attributeValue, x => x.Name), IsPreSelected = attributeValue.IsPreSelected }; attributeModel.Values.Add(valueModel); } } switch (attribute.AttributeControlType) { case AttributeControlType.DropdownList: case AttributeControlType.RadioList: case AttributeControlType.Checkboxes: { if (!string.IsNullOrEmpty(vendorAttributesXml)) { //clear default selection foreach (var item in attributeModel.Values) { item.IsPreSelected = false; } //select new values var selectedValues = _vendorAttributeParser.ParseVendorAttributeValues(vendorAttributesXml); 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(vendorAttributesXml)) { var enteredText = _vendorAttributeParser.ParseValues(vendorAttributesXml, 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); }
protected virtual void UpdateValueLocales(VendorAttributeValue vendorAttributeValue, VendorAttributeValueModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(vendorAttributeValue, x => x.Name, localized.Name, localized.LanguageId); } }
/// <returns>A task that represents the asynchronous operation</returns> protected virtual async Task UpdateValueLocalesAsync(VendorAttributeValue vendorAttributeValue, VendorAttributeValueModel model) { foreach (var localized in model.Locales) { await _localizedEntityService.SaveLocalizedValueAsync(vendorAttributeValue, x => x.Name, localized.Name, localized.LanguageId); } }