public async void Sucess(string result) { HostelAdmission = new HostelAdmission(); await App.Current.MainPage.DisplayAlert("HMS", result, "OK"); OnPropertyChanged("HostelAdmission"); }
public async void SaveHostelAdmission(HostelAdmission hostelAdmission) { HostelAdmissionResponse hostelAdmissionResponse; HostelAdmissionErrorResponse hostelAdmissionErrorResponse; try { UserDialogs.Instance.ShowLoading(); var client = new HttpClient(); client.BaseAddress = new Uri(ApplicationURL.BaseURL); string jsn = JsonConvert.SerializeObject(hostelAdmission); var content = new StringContent(jsn, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(ApplicationURL.HostelAdmission, content); if ((int)response.StatusCode == 200) { UserDialogs.Instance.HideLoading(); string resultHostel = await response.Content.ReadAsStringAsync(); hostelAdmissionResponse = JsonConvert.DeserializeObject <HostelAdmissionResponse>(resultHostel); hostelAdmissionI.Sucess(hostelAdmissionResponse.message); } else { UserDialogs.Instance.HideLoading(); string resultHostel = await response.Content.ReadAsStringAsync(); hostelAdmissionErrorResponse = JsonConvert.DeserializeObject <HostelAdmissionErrorResponse>(resultHostel); hostelAdmissionI.failed(hostelAdmissionErrorResponse.errors[0].message); } } catch (Exception ex) { UserDialogs.Instance.HideLoading(); await App.Current.MainPage.DisplayAlert("HMS", ex.ToString(), "OK"); } }