コード例 #1
0
        public async void GetProfiile(string studentId)
        {
            try
            {
                UserDialogs.Instance.ShowLoading();
                var client = new HttpClient();
                client.BaseAddress = new Uri(ApplicationURL.BaseURL);


                client.DefaultRequestHeaders.Add("studentId", studentId);

                HttpResponseMessage response = await client.GetAsync(ApplicationURL.GetProfiile);

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

                if ((int)response.StatusCode == 200)
                {
                    ObservableCollection <StudentProfileModel> profile = JsonConvert.DeserializeObject <ObservableCollection <StudentProfileModel> >(result);
                    if (profile.Count != 0)
                    {
                        UserDialogs.Instance.HideLoading();
                        profileCallback.LoadStudentProfile(profile);
                    }
                    else
                    {
                        UserDialogs.Instance.HideLoading();
                        await profileCallback.ServiceFaild();
                    }
                }
                else
                {
                    UserDialogs.Instance.HideLoading();
                    await profileCallback.ServiceFaild();

                    await App.Current.MainPage.DisplayAlert(" ", "Data Error", "OK");
                }
            }
            catch (Exception ex)
            {
                UserDialogs.Instance.HideLoading();
                await profileCallback.ServiceFaild();
            }

            //return response;
        }
コード例 #2
0
        public async void GetWardenprofile(string userId)
        {
            try
            {
                UserDialogs.Instance.ShowLoading();
                var client = new HttpClient();
                client.BaseAddress = new Uri(ApplicationURL.BaseURL);
                client.DefaultRequestHeaders.Add("userId", userId);
                HttpResponseMessage response = await client.GetAsync(ApplicationURL.WardenProfile);

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

                if ((int)response.StatusCode == 200)
                {
                    ObservableCollection <WardenProfileModel> parentleave = JsonConvert.DeserializeObject <ObservableCollection <WardenProfileModel> >(result);
                    if (parentleave.Count != 0)
                    {
                        for (int i = 0; i < parentleave.Count; i++)
                        {
                            parentleave[i].serialno = (i + 1).ToString();
                        }
                        UserDialogs.Instance.HideLoading();
                        profileI.Loadwardenprofile(parentleave);
                    }
                }
                else
                {
                    UserDialogs.Instance.HideLoading();
                    await profileI.ServiceFaild();
                }
            }
            catch
            {
                UserDialogs.Instance.HideLoading();
                await profileI.ServiceFaild();
            }
        }