public void UpdateValueLocales(CheckoutAttributeValue checkoutAttributeValue, CheckoutAttributeValueModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(checkoutAttributeValue, x => x.Name, localized.Name, localized.LanguageId); } }
protected virtual List <LocalizedProperty> UpdateValueLocales(CheckoutAttributeValue checkoutAttributeValue, CheckoutAttributeValueModel 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, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); } } return(localized); }
public virtual ActionResult ValueCreatePopup(string btnId, string formId, CheckoutAttributeValueModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes)) { return(AccessDeniedView()); } var checkoutAttribute = _checkoutAttributeService.GetCheckoutAttributeById(model.CheckoutAttributeId); if (checkoutAttribute == null) { //No checkout attribute found with the specified id return(RedirectToAction("List")); } model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode; model.BaseWeightIn = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name; if (checkoutAttribute.AttributeControlType == AttributeControlType.ColorSquares) { //ensure valid color is chosen/entered if (String.IsNullOrEmpty(model.ColorSquaresRgb)) { ModelState.AddModelError("", "Color is required"); } try { //ensure color is valid (can be instanciated) System.Drawing.ColorTranslator.FromHtml(model.ColorSquaresRgb); } catch (Exception exc) { ModelState.AddModelError("", exc.Message); } } if (ModelState.IsValid) { var cav = new CheckoutAttributeValue { CheckoutAttributeId = model.CheckoutAttributeId, Name = model.Name, ColorSquaresRgb = model.ColorSquaresRgb, PriceAdjustment = model.PriceAdjustment, WeightAdjustment = model.WeightAdjustment, IsPreSelected = model.IsPreSelected, DisplayOrder = model.DisplayOrder }; _checkoutAttributeService.InsertCheckoutAttributeValue(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(CheckoutAttributeValue checkoutAttributeValue, CheckoutAttributeValueModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(checkoutAttributeValue, x => x.Name, localized.Name, localized.LanguageId); } }
public static CheckoutAttributeValue ToEntity(this CheckoutAttributeValueModel model, CheckoutAttributeValue destination) { return(Mapper.Map(model, destination)); }
public ActionResult ValueEditPopup(string btnId, string formId, CheckoutAttributeValueModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) return AccessDeniedView(); var cav = _checkoutAttributeService.GetCheckoutAttributeValueById(model.Id); if (cav == null) //No checkout attribute value found with the specified id return RedirectToAction("List"); model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode; model.BaseWeightIn = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name; if (ModelState.IsValid) { cav = model.ToEntity(cav); _checkoutAttributeService.UpdateCheckoutAttributeValue(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.ManageAttributes)) return AccessDeniedView(); var cav = _checkoutAttributeService.GetCheckoutAttributeValueById(id); if (cav == null) //No checkout attribute value found with the specified id return RedirectToAction("List"); var model = new CheckoutAttributeValueModel { CheckoutAttributeId = cav.CheckoutAttributeId, Name = cav.Name, ColorSquaresRgb = cav.ColorSquaresRgb, DisplayColorSquaresRgb = cav.CheckoutAttribute.AttributeControlType == AttributeControlType.ColorSquares, PriceAdjustment = cav.PriceAdjustment, WeightAdjustment = cav.WeightAdjustment, IsPreSelected = cav.IsPreSelected, DisplayOrder = cav.DisplayOrder, PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode, BaseWeightIn = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name }; //locales AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.Name = cav.GetLocalized(x => x.Name, languageId, false, false); }); return View(model); }
public virtual IActionResult ValueEditPopup(CheckoutAttributeValueModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes)) { return(AccessDeniedView()); } //try to get a checkout attribute value with the specified id var checkoutAttributeValue = _checkoutAttributeService.GetCheckoutAttributeValueById(model.Id); if (checkoutAttributeValue == null) { return(RedirectToAction("List")); } //try to get a checkout attribute with the specified id var checkoutAttribute = _checkoutAttributeService.GetCheckoutAttributeById(checkoutAttributeValue.CheckoutAttributeId); if (checkoutAttribute == null) { return(RedirectToAction("List")); } model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode; model.BaseWeightIn = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name; if (checkoutAttribute.AttributeControlType == AttributeControlType.ColorSquares) { //ensure valid color is chosen/entered if (string.IsNullOrEmpty(model.ColorSquaresRgb)) { ModelState.AddModelError(string.Empty, "Color is required"); } try { //ensure color is valid (can be instantiated) System.Drawing.ColorTranslator.FromHtml(model.ColorSquaresRgb); } catch (Exception exc) { ModelState.AddModelError(string.Empty, exc.Message); } } if (ModelState.IsValid) { checkoutAttributeValue = model.ToEntity(checkoutAttributeValue); _checkoutAttributeService.UpdateCheckoutAttributeValue(checkoutAttributeValue); UpdateValueLocales(checkoutAttributeValue, model); ViewBag.RefreshPage = true; return(View(model)); } //prepare model model = _checkoutAttributeModelFactory.PrepareCheckoutAttributeValueModel(model, checkoutAttribute, checkoutAttributeValue, true); //if we got this far, something failed, redisplay form return(View(model)); }
protected virtual List <LocalizedProperty> UpdateValueLocales(CheckoutAttributeValue checkoutAttributeValue, CheckoutAttributeValueModel 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); }
public virtual CheckoutAttributeValue UpdateCheckoutAttributeValueModel(CheckoutAttribute checkoutAttribute, CheckoutAttributeValue checkoutAttributeValue, CheckoutAttributeValueModel model) { checkoutAttributeValue = model.ToEntity(checkoutAttributeValue); _checkoutAttributeService.UpdateCheckoutAttribute(checkoutAttribute); return(checkoutAttributeValue); }
public ActionResult ValueCreatePopup(string btnId, string formId, CheckoutAttributeValueModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) return AccessDeniedView(); var checkoutAttribute = _checkoutAttributeService.GetCheckoutAttributeById(model.CheckoutAttributeId); if (checkoutAttribute == null) throw new ArgumentException("No checkout attribute found with the specified id"); model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode; model.BaseWeightIn = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name; if (ModelState.IsValid) { var sao = model.ToEntity(); _checkoutAttributeService.InsertCheckoutAttributeValue(sao); UpdateValueLocales(sao, 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 virtual CheckoutAttributeValue InsertCheckoutAttributeValueModel(CheckoutAttribute checkoutAttribute, CheckoutAttributeValueModel model) { var cav = model.ToEntity(); checkoutAttribute.CheckoutAttributeValues.Add(cav); _checkoutAttributeService.UpdateCheckoutAttribute(checkoutAttribute); return(cav); }
public virtual async Task <CheckoutAttributeValue> UpdateCheckoutAttributeValueModel(CheckoutAttribute checkoutAttribute, CheckoutAttributeValue checkoutAttributeValue, CheckoutAttributeValueModel model) { checkoutAttributeValue = model.ToEntity(checkoutAttributeValue); await _checkoutAttributeService.UpdateCheckoutAttribute(checkoutAttribute); return(checkoutAttributeValue); }
public static CheckoutAttributeValue ToEntity(this CheckoutAttributeValueModel model, CheckoutAttributeValue entity) { MapperFactory.Map(model, entity); return(entity); }
protected virtual List<LocalizedProperty> UpdateValueLocales(CheckoutAttributeValue checkoutAttributeValue, CheckoutAttributeValueModel 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, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); } return localized; }
/// <summary> /// Prepare checkout attribute value model /// </summary> /// <param name="model">Checkout attribute value model</param> /// <param name="checkoutAttribute">Checkout attribute</param> /// <param name="checkoutAttributeValue">Checkout attribute value</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Checkout attribute value model</returns> public virtual CheckoutAttributeValueModel PrepareCheckoutAttributeValueModel(CheckoutAttributeValueModel model, CheckoutAttribute checkoutAttribute, CheckoutAttributeValue checkoutAttributeValue, bool excludeProperties = false) { if (checkoutAttribute == null) { throw new ArgumentNullException(nameof(checkoutAttribute)); } Action <CheckoutAttributeValueLocalizedModel, int> localizedModelConfiguration = null; if (checkoutAttributeValue != null) { //fill in model values from the entity model = model ?? checkoutAttributeValue.ToModel <CheckoutAttributeValueModel>(); //define localized model configuration action localizedModelConfiguration = (locale, languageId) => { locale.Name = _localizationService.GetLocalized(checkoutAttributeValue, entity => entity.Name, languageId, false, false); }; } model.CheckoutAttributeId = checkoutAttribute.Id; model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode; model.BaseWeightIn = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name; model.DisplayColorSquaresRgb = checkoutAttribute.AttributeControlType == AttributeControlType.ColorSquares; //prepare localized models if (!excludeProperties) { model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration); } return(model); }
//create public ActionResult ValueCreatePopup(int checkoutAttributeId) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) return AccessDeniedView(); var model = new CheckoutAttributeValueModel(); model.CheckoutAttributeId = checkoutAttributeId; model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode; model.BaseWeightIn = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name; //locales AddLocales(_languageService, model.Locales); return View(model); }
public static CheckoutAttributeValue ToEntity(this CheckoutAttributeValueModel model) { return(model.MapTo <CheckoutAttributeValueModel, CheckoutAttributeValue>()); }
//create public ActionResult ValueCreatePopup(int checkoutAttributeId) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes)) return AccessDeniedView(); var checkoutAttribute = _checkoutAttributeService.GetCheckoutAttributeById(checkoutAttributeId); var model = new CheckoutAttributeValueModel(); model.CheckoutAttributeId = checkoutAttributeId; model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode; model.BaseWeightIn = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name; //color squares model.DisplayColorSquaresRgb = checkoutAttribute.AttributeControlType == AttributeControlType.ColorSquares; model.ColorSquaresRgb = "#000000"; //locales AddLocales(_languageService, model.Locales); return View(model); }
public static CheckoutAttributeValue ToEntity(this CheckoutAttributeValueModel model) { return(Mapper.Map <CheckoutAttributeValueModel, CheckoutAttributeValue>(model)); }
public ActionResult ValueEditPopup(string btnId, string formId, CheckoutAttributeValueModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes)) return AccessDeniedView(); var cav = _checkoutAttributeService.GetCheckoutAttributeValueById(model.Id); if (cav == null) //No checkout attribute value found with the specified id return RedirectToAction("List"); model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode; model.BaseWeightIn = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name; if (cav.CheckoutAttribute.AttributeControlType == AttributeControlType.ColorSquares) { //ensure valid color is chosen/entered if (String.IsNullOrEmpty(model.ColorSquaresRgb)) ModelState.AddModelError("", "Color is required"); try { //ensure color is valid (can be instanciated) System.Drawing.ColorTranslator.FromHtml(model.ColorSquaresRgb); } catch (Exception exc) { ModelState.AddModelError("", exc.Message); } } if (ModelState.IsValid) { cav.Name = model.Name; cav.ColorSquaresRgb = model.ColorSquaresRgb; cav.PriceAdjustment = model.PriceAdjustment; cav.WeightAdjustment = model.WeightAdjustment; cav.IsPreSelected = model.IsPreSelected; cav.DisplayOrder = model.DisplayOrder; _checkoutAttributeService.UpdateCheckoutAttributeValue(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 async Task UpdateValueLocalesAsync(CheckoutAttributeValue checkoutAttributeValue, CheckoutAttributeValueModel model) { foreach (var localized in model.Locales) { await _localizedEntityService.SaveLocalizedValueAsync(checkoutAttributeValue, x => x.Name, localized.Name, localized.LanguageId); } }