Esempio n. 1
0
        public async Task <KooshDaroo.Models.Pharmacy> PostPharmacyAsync(KooshDaroo.Models.Pharmacy pharmacy)
        {
            //RestClient<Pharmacy> restClient = new RestClient<Pharmacy>();
            //Pharmacy r = await restClient.PostAsync("Pharmacy",pharmacy);

            var         httpClient  = new HttpClient();
            var         json        = JsonConvert.SerializeObject(pharmacy);
            HttpContent httpContent = new StringContent(json);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            try
            {
                var result = await httpClient.PostAsync(App.apiAddress + "Pharmacy/", httpContent);

                var jsonString = await result.Content.ReadAsStringAsync();

                var r = JsonConvert.DeserializeObject <KooshDaroo.Models.Pharmacy>(jsonString);

                return(r);
            }
            catch (Exception ex)
            {
                return(pharmacy);
            }
        }
        private async void SignUpButton_Clicked(object sender, EventArgs e)
        {
            PharmacyService Pharmacyservice = new PharmacyService();
            var             _pharmacyS      = await Pharmacyservice.GetPharmacyByPhoneNoAsync(phoneNo.Text);

            GetCurrentXY();
            if (x == 0 & y == 0)
            {
                return;
            }

            if (_pharmacyS.Count == 0)
            {
                KooshDaroo.Models.Pharmacy _pharmacy = new KooshDaroo.Models.Pharmacy {
                    City = city.SelectedItem.ToString(), Title = pharmacy.Text, X = x, Y = y, PhoneNo = phoneNo.Text, is24h = is24h.IsChecked
                };
                var result = Pharmacyservice.PostPharmacyAsync(_pharmacy);
                App.myId      = result.Result.id;
                App.myPhoneNo = result.Result.PhoneNo;
            }
            else
            {
                App.myId      = _pharmacyS[0].id;
                App.myPhoneNo = _pharmacyS[0].PhoneNo;
            }
            KooshDarooDatabase odb         = new KooshDarooDatabase();
            tblPharmacy        newPharmacy = new tblPharmacy {
                City = city.SelectedItem.ToString(), Title = pharmacy.Text, X = x, Y = y, PhoneNo = phoneNo.Text, is24h = is24h.IsChecked
            };
            int r = await odb.SavePharmacyAsync(newPharmacy);

            //odb = new KooshDarooDatabase();
            //var oLoginItemS = odb.GetPharmacysAsync();
            //var o = oLoginItemS.Result.Count;

            App.Current.MainPage = new NavigationPage(new MainPageTabbed());
            //App.Current.MainPage = new MainPageTabbed();
            //App.Current.MainPage = new PrescribesListPage();
            //await this.Navigation.PushAsync(new PrescribesListPage());
        }