/// <summary> /// 保存(添加或修改)收货地址 /// <para>Service Url: http://devbtp.sv.iuoooo.com/Jinher.AMP.BTP.SV.DeliveryAddressSV.svc/SaveDeliveryAddressNew /// </para> /// </summary> /// <param name="addressDTO">地址实体</param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO SaveDeliveryAddressNewExt(Jinher.AMP.BTP.Deploy.CustomDTO.AddressSDTO addressDTO) { try { ResultDTO result = ValidAddressNew(addressDTO); if (result.ResultCode != 0) { return(result); } ContextSession contextSession = ContextFactory.CurrentThreadContext; DeliveryAddress deliveryAddress = null; if (addressDTO.AddressId != Guid.Empty) { deliveryAddress = DeliveryAddress.ObjectSet().Where(n => n.Id == addressDTO.AddressId).FirstOrDefault(); } if (deliveryAddress == null) { deliveryAddress = DeliveryAddress.CreateDeliveryAddress(); deliveryAddress.Id = Guid.NewGuid(); } else { deliveryAddress.EntityState = System.Data.EntityState.Modified; } deliveryAddress.Name = ""; if (addressDTO.UserId != Guid.Empty) { deliveryAddress.UserId = addressDTO.UserId; } deliveryAddress.AppId = addressDTO.AppId; deliveryAddress.RecipientsUserName = addressDTO.ReceiptUserName; deliveryAddress.RecipientsPhone = addressDTO.ReceiptPhone; deliveryAddress.RecipientsAddress = addressDTO.ReceiptAddress; deliveryAddress.Province = addressDTO.Province; deliveryAddress.City = addressDTO.City; deliveryAddress.District = addressDTO.District; deliveryAddress.Street = addressDTO.Street; deliveryAddress.RecipientsZipCode = addressDTO.RecipientsZipCode; deliveryAddress.ProvinceCode = addressDTO.ProvinceCode; deliveryAddress.CityCode = addressDTO.CityCode; deliveryAddress.DistrictCode = addressDTO.DistrictCode; deliveryAddress.StreetCode = addressDTO.StreetCode; deliveryAddress.IsDefault = addressDTO.IsDefault == 1 ? true : false; if (addressDTO.IsDefault == 1) { DeliveryAddress.ObjectSet().Context.ExecuteStoreCommand("update DeliveryAddress set IsDefault=0 where UserId='" + deliveryAddress.UserId + "'"); } contextSession.SaveObject(deliveryAddress); contextSession.SaveChanges(); } catch (Exception ex) { LogHelper.Error(string.Format("SaveDeliveryAddressNewExt异常。addressDTO:{0},异常信息:{1}", addressDTO, ex)); return(new ResultDTO { ResultCode = 1, Message = "Error" }); } return(new ResultDTO { ResultCode = 0, Message = "Success" }); }