public override async Task <IDisplayResult> UpdateAsync(PricePart pricePart, IUpdateModel updater, UpdatePartEditorContext context)
        {
            var updateModel = new PricePartViewModel();

            if (await updater.TryUpdateModelAsync(updateModel, Prefix, t => t.PriceValue, t => t.PriceCurrency))
            {
                pricePart.Price = _moneyService.Create(updateModel.PriceValue, updateModel.PriceCurrency);
            }

            return(Edit(pricePart, context));
        }
예제 #2
0
        public override async Task <IDisplayResult> UpdateAsync(PricePart model, IUpdateModel updater)
        {
            var updateModel = new PricePartViewModel();
            await updater.TryUpdateModelAsync(updateModel, Prefix, t => t.PriceValue);

            await updater.TryUpdateModelAsync(updateModel, Prefix, t => t.PriceCurrency);

            model.Price = _moneyService.Create(updateModel.PriceValue, updateModel.PriceCurrency);

            return(Edit(model));
        }
예제 #3
0
        public override async Task <IDisplayResult> UpdateAsync(PriceVariantsPart part, IUpdateModel updater, UpdatePartEditorContext context)
        {
            var updateModel = new PriceVariantsPartViewModel();

            if (await updater.TryUpdateModelAsync(updateModel, Prefix, t => t.VariantsValues, t => t.VariantsCurrencies))
            {
                // Remove any content or the variants would be merged and not be cleared
                part.Content.Variants.RemoveAll();

                part.Variants = updateModel.VariantsValues
                                .Where(x => x.Value.HasValue &&
                                       updateModel.VariantsCurrencies?.ContainsKey(x.Key) == true &&
                                       updateModel.VariantsCurrencies[x.Key] != Currency.UnspecifiedCurrency.CurrencyIsoCode)
                                .ToDictionary(x => x.Key,
                                              x => _moneyService.Create(x.Value.Value, updateModel.VariantsCurrencies[x.Key]));
            }

            return(Edit(part, context));
        }