/// <summary> /// 更新门店配送范围 /// </summary> /// <param name="shopBranch"></param> public static void UpdateShopDeliveryScope(DeliveryScope deliveryScope) { AutoMapper.Mapper.CreateMap <DeliveryScope, DeliveryScopeInfo>(); var shopDeliveryScopeInfo = AutoMapper.Mapper.Map <DeliveryScope, DeliveryScopeInfo>(deliveryScope); _shopBranchService.UpdateShopDeliveryScope(shopDeliveryScopeInfo); }
public ActionResult Add(ShopBranch shopBranch) { try { if (!string.Equals(shopBranch.PasswordOne, shopBranch.PasswordTwo)) { throw new HimallException("两次密码输入不一致!"); } if (string.IsNullOrWhiteSpace(shopBranch.PasswordOne) || string.IsNullOrWhiteSpace(shopBranch.PasswordTwo)) { throw new HimallException("密码不能为空!"); } if (shopBranch.ShopBranchName.Length > 15) { throw new HimallException("门店名称不能超过15个字!"); } if (shopBranch.AddressDetail.Length > 50) { throw new HimallException("详细地址不能超过50个字!"); } if (shopBranch.Latitude <= 0 || shopBranch.Longitude <= 0) { throw new HimallException("请搜索地址地图定位!"); } string regionIDList = Request.Form["txtRegionScop"]; string regionNameList = Request.Form["txtRegionScopName"]; string[] regionIdArr = regionIDList.Split(','); string[] regionNameArr = regionNameList.Split(','); if (shopBranch.ServeRadius <= 0 && string.IsNullOrWhiteSpace(regionIDList.Trim())) { throw new HimallException("配送半径和配送范围不能同时为空!"); } shopBranch.ShopId = CurrentSellerManager.ShopId; shopBranch.CreateDate = DateTime.Now; long shopBranchId; ShopBranchApplication.AddShopBranch(shopBranch, out shopBranchId); if (shopBranchId > 0) { #region 添加门店配送范围 List <DeliveryScope> deliveryScopList = new List <DeliveryScope>(); List <int> regionIdList = new List <int>(); DeliveryScope info = null; for (int i = 0; i < regionIdArr.Length; i++) { int tempRegionId = 0; if (int.TryParse(regionIdArr[i], out tempRegionId) && regionNameArr.Length >= i) { regionIdList.Add(tempRegionId); if (!ShopBranchApplication.ExistsShopDeliveryScope(new ShopDeliveryScopeQuery() { ShopBranchId = shopBranchId, RegionId = tempRegionId })) { info = new DeliveryScope(); info.RegionId = tempRegionId; info.RegionName = regionNameArr[i]; info.FullRegionPath = RegionApplication.GetRegionPath(tempRegionId); info.FullRegionPath = CommonConst.ADDRESS_PATH_SPLIT + info.FullRegionPath + CommonConst.ADDRESS_PATH_SPLIT;//默认在结尾增加分隔符 info.ShopBranchId = shopBranchId; deliveryScopList.Add(info); } } } if (deliveryScopList.Count > 0) { ShopBranchApplication.AddShopDeliveryScope(deliveryScopList); } if (regionIdList.Count > 0) { ShopBranchApplication.DeleteShopDeliveryScope(new ShopDeliveryScopeQuery() { RegionIdList = regionIdList, ShopBranchId = shopBranchId }); //清除旧数据 } #endregion } } catch (Exception ex) { return(Json(new Result() { success = false, msg = ex.Message })); } return(Json(new Result() { success = true })); }