public void Save(ByWeightShippingRulesModel model) { var method = _service.Find(model.ShippingMethodId); var rules = model.Rules.Select(r => new ByWeightShippingRule { FromWeight = Convert.ToDecimal(r.FromWeight), ToWeight = Convert.ToDecimal(r.ToWeight), PriceUnit = (ShippingPriceUnit)Enum.Parse(typeof(ShippingPriceUnit), r.PriceUnit), ShippingPrice = Convert.ToDecimal(r.ShippingPrice) }) .ToList(); method.UpdateShippingRateProviderConfig(new ByWeightShippingRateProviderConfig { Rules = rules }); }
public ActionResult Load(int methodId) { var method = _service.GetById(methodId); var rules = new List<ByWeightShippingRuleModel>(); if (!String.IsNullOrWhiteSpace(method.ShippingRateProviderData)) { rules = JsonConvert.DeserializeObject<List<ByWeightShippingRuleModel>>(method.ShippingRateProviderData); } var model = new ByWeightShippingRulesModel { ShippingMethodId = methodId, Rules = rules }; return Json(model, JsonRequestBehavior.AllowGet); }
public ActionResult Load(int methodId) { var method = _service.Find(methodId); var config = method.LoadShippingRateProviderConfig<ByWeightShippingRateProviderConfig>() ?? new ByWeightShippingRateProviderConfig(); var ruleModels = config.Rules.Select(r => new ByWeightShippingRuleModel { FromWeight = r.FromWeight.ToString(), ToWeight = r.ToWeight.ToString(), ShippingPrice = r.ShippingPrice.ToString(), PriceUnit = r.PriceUnit.ToString() }) .ToList(); var model = new ByWeightShippingRulesModel { ShippingMethodId = methodId, Rules = ruleModels }; return Json(model, JsonRequestBehavior.AllowGet); }
public void Save(ByWeightShippingRulesModel model) { var method = _service.GetById(model.ShippingMethodId); method.ShippingRateProviderData = JsonConvert.SerializeObject(model.Rules); }