/// <summary> /// 修改 /// </summary> /// <returns></returns> public async Task Update(CreateOrUpdateInput input) { Place place = _placeManager.Get(input.Id); if (place != null) { if (input.Code != place.Code) { var query = _placeManager.GetSonByCode(place.Code); List <Place> placeList = query.ToList(); foreach (var item in placeList) { item.Code = input.Code; } } else { place.Name = input.Name; //await _placeRepository.UpdateAsync(place); } } else { throw new UserFriendlyException("城市信息丢失!"); } }
/// <summary> /// 新增 /// </summary> /// <returns></returns> public async Task Create(CreateOrUpdateInput input) { if (!_placeManager.GetAll().Any(p => p.Code == input.Code)) { Place place = new Place(); place.Name = input.Name; place.Code = input.Code; if (input.ParentId != 0) { Place parentPlace = _placeManager.Get(input.ParentId); if (parentPlace != null) { place.Deep = parentPlace.Deep + 1; place.ParentCode = parentPlace.Code; } else { throw new UserFriendlyException("父级城市信息丢失!"); } } else { place.Deep = 1; place.ParentCode = "0"; } await _placeRepository.InsertAsync(place); } else { throw new UserFriendlyException("城市编号已使用!"); } }