コード例 #1
0
        public async void UpdateCourse(UpdateCourseModel updateCourseModel)
        {
            ProfileUpdateResponse      profileUpdateResponse;
            ProfileUpdateErrorresponse profileUpdateErrorresponse;

            try
            {
                UserDialogs.Instance.ShowLoading();
                var client = new HttpClient();
                client.BaseAddress = new Uri(ApplicationURL.BaseURL);

                string jsn = JsonConvert.SerializeObject(updateCourseModel);

                var content = new StringContent(jsn, Encoding.UTF8, "application/json");

                HttpResponseMessage response = await client.PostAsync(ApplicationURL.UpdateCourse, content);

                if ((int)response.StatusCode == 200)
                {
                    UserDialogs.Instance.HideLoading();
                    string resultHostel = await response.Content.ReadAsStringAsync();

                    profileUpdateResponse = JsonConvert.DeserializeObject <ProfileUpdateResponse>(resultHostel);
                    ieditcourse.UpdateSucess(profileUpdateResponse.message);
                }
                else
                {
                    UserDialogs.Instance.HideLoading();
                    string resultHostel = await response.Content.ReadAsStringAsync();

                    profileUpdateErrorresponse = JsonConvert.DeserializeObject <ProfileUpdateErrorresponse>(resultHostel);
                    ieditcourse.servicefailed(profileUpdateErrorresponse.errors[0].message);
                }
            }
            catch (Exception ex)
            {
                UserDialogs.Instance.HideLoading();
                await App.Current.MainPage.DisplayAlert("HMS", ex.ToString(), "OK");
            }
        }