Пример #1
0
        /// <summary>
        /// 删除地址
        /// </summary>
        private async void DeleteAddress()
        {
            try
            {
                SimpleRD simpleRD = await RestSharpService.DeleteAddressById(AddressId);

                if (simpleRD.success)
                {
                    CrossToastPopUp.Current.ShowToastSuccess("删除成功!", ToastLength.Long);
                    await Application.Current.MainPage.Navigation.PopAsync();
                }
                else
                {
                    CrossToastPopUp.Current.ShowToastError(simpleRD.message, ToastLength.Long);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #2
0
        public AddressManageViewModel()
        {
            AddressList = new ObservableCollection <AddressInfo>();

            EditCommand = new Command <AddressInfo>((address) =>
            {
                //AddressInfo addressInfo = new AddressInfo();
                //
                //foreach (var item in AddressList)
                //{
                //    if (item.addressId == address.addressId)
                //    {
                //        addressInfo = item;
                //        break;
                //    }
                //}

                EditAddressPage editAddressPage = new EditAddressPage(address);
                Application.Current.MainPage.Navigation.PushAsync(editAddressPage);
            }, (id) => { return(true); });

            DeleteCommand = new Command <AddressInfo>(async(address) =>
            {
                try
                {
                    SimpleRD simpleRD = await RestSharpService.DeleteAddressById(address.addressId);

                    if (simpleRD.success)
                    {
                        CrossToastPopUp.Current.ShowToastSuccess("删除成功!", ToastLength.Long);
                        InitAddressList();
                    }
                    else
                    {
                        CrossToastPopUp.Current.ShowToastError(simpleRD.message, ToastLength.Long);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }, (address) => { return(true); });

            SetDefaultCommand = new Command <AddressInfo>(async(address) =>
            {
                try
                {
                    if (!Tools.IsNetConnective())
                    {
                        CrossToastPopUp.Current.ShowToastError("无网络连接,请检查网络。", ToastLength.Long);
                        return;
                    }

                    address.isDefault = true;

                    SimpleRD simpleRD = await RestSharpService.UpdateAddress(address);

                    if (simpleRD.success)
                    {
                        CrossToastPopUp.Current.ShowToastSuccess("更新默认收货地址!", ToastLength.Long);
                        InitAddressList();
                    }
                    else
                    {
                        CrossToastPopUp.Current.ShowToastError(simpleRD.message, ToastLength.Long);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }, (address) => { return(true); });

            AddAddressCommand = new Command(() =>
            {
                EditAddressPage editAddressPage = new EditAddressPage();

                Application.Current.MainPage.Navigation.PushAsync(editAddressPage);
            }, () => { return(true); });

            RefreshCommand = new Command(() =>
            {
                InitAddressList();
                IsRefreshing = false;
            }, () => { return(true); });

            InitAddressList();
        }