public virtual async Task <IActionResult> ValueCreatePopup(CheckoutAttributeValueModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageAttributes)) { return(AccessDeniedView()); } //try to get a checkout attribute with the specified id var checkoutAttribute = await _checkoutAttributeService.GetCheckoutAttributeByIdAsync(model.CheckoutAttributeId); if (checkoutAttribute == null) { return(RedirectToAction("List")); } model.PrimaryStoreCurrencyCode = (await _currencyService.GetCurrencyByIdAsync(_currencySettings.PrimaryStoreCurrencyId)).CurrencyCode; model.BaseWeightIn = (await _measureService.GetMeasureWeightByIdAsync(_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) { var checkoutAttributeValue = model.ToEntity <CheckoutAttributeValue>(); await _checkoutAttributeService.InsertCheckoutAttributeValueAsync(checkoutAttributeValue); await UpdateValueLocalesAsync(checkoutAttributeValue, model); ViewBag.RefreshPage = true; return(View(model)); } //prepare model model = await _checkoutAttributeModelFactory.PrepareCheckoutAttributeValueModelAsync(model, checkoutAttribute, null, true); //if we got this far, something failed, redisplay form return(View(model)); }
public async Task SetUp() { _checkoutAttributeParser = GetService <ICheckoutAttributeParser>(); _checkoutAttributeFormatter = GetService <ICheckoutAttributeFormatter>(); _checkoutAttributeService = GetService <ICheckoutAttributeService>(); //color (dropdownlist) _ca1 = new CheckoutAttribute { Name = "Color", TextPrompt = "Select color:", IsRequired = true, AttributeControlType = AttributeControlType.DropdownList, DisplayOrder = 1 }; await _checkoutAttributeService.InsertCheckoutAttributeAsync(_ca1); _cav11 = new CheckoutAttributeValue { Name = "Green", DisplayOrder = 1, CheckoutAttributeId = _ca1.Id }; _cav12 = new CheckoutAttributeValue { Name = "Red", DisplayOrder = 2, CheckoutAttributeId = _ca1.Id }; await _checkoutAttributeService.InsertCheckoutAttributeValueAsync(_cav11); await _checkoutAttributeService.InsertCheckoutAttributeValueAsync(_cav12); //custom option (checkboxes) _ca2 = new CheckoutAttribute { Name = "Custom option", TextPrompt = "Select custom option:", IsRequired = true, AttributeControlType = AttributeControlType.Checkboxes, DisplayOrder = 2 }; await _checkoutAttributeService.InsertCheckoutAttributeAsync(_ca2); _cav21 = new CheckoutAttributeValue { Name = "Option 1", DisplayOrder = 1, CheckoutAttributeId = _ca2.Id }; _cav22 = new CheckoutAttributeValue { Name = "Option 2", DisplayOrder = 2, CheckoutAttributeId = _ca2.Id }; await _checkoutAttributeService.InsertCheckoutAttributeValueAsync(_cav21); await _checkoutAttributeService.InsertCheckoutAttributeValueAsync(_cav22); //custom text _ca3 = new CheckoutAttribute { Name = "Custom text", TextPrompt = "Enter custom text:", IsRequired = true, AttributeControlType = AttributeControlType.MultilineTextbox, DisplayOrder = 3 }; await _checkoutAttributeService.InsertCheckoutAttributeAsync(_ca3); }