Пример #1
0
        public async Task <P_Res_Buy_Thing> PostBuyThingInfo(Bought_thing bt)
        {
            User   userInfo     = (User)Application.Current.Properties["user"];
            int    user_id      = userInfo.id;
            string serverUrl    = ServerInfo.url;
            string searchAPIUrl = "/buy_things?";
            string reqUrl       = $"{serverUrl}{searchAPIUrl}?user_id={user_id}";
            //buy_things?user_id=1;

            string            jsonString = JsonConvert.SerializeObject(bt);
            WrappedHttpClient whc        = new WrappedHttpClient();
            var content = new StringContent(jsonString, Encoding.UTF8, "application/json");
            HttpResponseMessage response = await whc.PostAsync(reqUrl, content);

            string result = await response.Content.ReadAsStringAsync();

            P_Res_Buy_Thing prbt = JsonConvert.DeserializeObject <P_Res_Buy_Thing>(result);

            return(prbt);
        }
        //個数はここで決めてもらう
        async void OkDoneBtnClicked(object sender, EventArgs s)
        {
            //入力した個数を取得
            //thingsNumは個数
            int itemNum = 1;

            if (int.TryParse(numInput.Text, out itemNum))  //数値に変換できた場合itemNumに入る
            //数を取得
            {
                bt.num = itemNum;
                //サーバにPost
                PostJson        pj   = new PostJson();
                P_Res_Buy_Thing prbt = await pj.PostBuyThingInfo(bt);

                //Todo:なにかメッセージ表示する
                await DisplayAlert("登録完了", prbt.updated_at.ToString("D"), "OK");

                //ページを離れる
                if (Navigation.NavigationStack.Count == 4)
                {
                    if (Device.RuntimePlatform == Device.Android)
                    {
                        Navigation.RemovePage(Navigation.NavigationStack[Navigation.NavigationStack.Count - 1]);
                    }
                    else
                    {
                        Navigation.RemovePage(Navigation.NavigationStack[Navigation.NavigationStack.Count - 2]);
                    }
                }
                await Navigation.PopAsync();
            }
            else    //Inputが数字以外
            //正しい入力を促す
            {
                DependencyService.Get <IMyFormsToast>().Show("Number ERROR: 数字を入力してください");
            }
        }