public ActionResult Edit(Guid?id = null) { ShippingArea shippingArea = null; var shippingCodeList = new string[] { }; if (id != null && id != Guid.Empty) { shippingArea = _shippingAreaService.GetById(id.Value); ViewBag.IsNew = false; List <ShippingAreaFee> feeList = _shippingAreaService.GetFeeListByShippingAreaId(id.Value); ViewBag.FeeList = feeList; ViewBag.CodeList = feeList.Select(x => x.AreaId).ToArray(); } if (shippingArea == null) { shippingArea = new ShippingArea { Id = KeyGenerator.GetGuidKey(), IsDefualt = DefaultStatus.Normal }; ViewBag.IsNew = true; } var drovinceList = _currencyService.GetList <District>( d => d.ParentId.Equals("0", StringComparison.OrdinalIgnoreCase)).Select(x => new DistrictWithChilViewModel { Id = x.Id, ParentId = x.ParentId, ShortName = x.ShortName, Sort = x.Sort, DistrictChil = _currencyService.GetList <District>( d => d.ParentId.Equals(x.Id, StringComparison.OrdinalIgnoreCase)).Select(y => new DistrictViewModel { Id = y.Id, ParentId = y.ParentId, ShortName = y.ShortName, Sort = y.Sort }).ToList() }).ToList(); ViewBag.DrovinceList = drovinceList; return(View(shippingArea)); }
public ActionResult EditOnPost(ShippingAreaViewModel postModel) { var result = new DataJsonResult(); var shippingArea = _currencyService.GetSingleById <ShippingArea>(postModel.Id); var isNew = false; if (postModel.AreaId == null || postModel.AreaId.Count == 0) { result.ErrorMessage = "请选择区域"; } else { var areaNames = ""; List <ShippingAreaFee> feeList = new List <ShippingAreaFee>(); foreach (var areaId in postModel.AreaId) { ShippingAreaFee feeInfo = new ShippingAreaFee(); feeInfo.Id = KeyGenerator.GetGuidKey(); feeInfo.ShippingAreaId = postModel.Id; feeInfo.AreaId = areaId; feeInfo.AreaName = _currencyService.GetSingleById <District>(areaId).FullName; feeInfo.Freight = postModel.Freight; feeInfo.Weight = postModel.Weight; feeInfo.SFreight = postModel.SFreight; feeInfo.IsDefualt = postModel.IsDefualt; feeList.Add(feeInfo); areaNames += feeInfo.AreaName + ","; } areaNames = areaNames.Substring(0, areaNames.Length - 1); if (shippingArea == null) { shippingArea = new ShippingArea { Id = postModel.Id, Name = postModel.Name, AreaNames = areaNames, Freight = postModel.Freight, Sort = postModel.Sort, Weight = postModel.Weight, SFreight = postModel.SFreight, IsDefualt = postModel.IsDefualt }; isNew = true; } else { shippingArea.Name = postModel.Name; shippingArea.AreaNames = areaNames; shippingArea.Freight = postModel.Freight; shippingArea.Sort = postModel.Sort; shippingArea.Weight = postModel.Weight; shippingArea.SFreight = postModel.SFreight; shippingArea.IsDefualt = postModel.IsDefualt; } result.Success = _shippingAreaService.SaveInfo(shippingArea, feeList, isNew); } return(Json(result)); }