예제 #1
0
        public async void sucess(string result)
        {
            CreateLeaveTypeModel = new CreateLeaveTypeModel();
            await App.Current.MainPage.DisplayAlert("HMS", result, "OK");

            OnPropertyChanged("CreateLeaveTypeModel");
        }
예제 #2
0
        public async void CreateLeaveType(CreateLeaveTypeModel createLeaveTypeModel)
        {
            CourseResponse      courseResponse;
            CourseErrorResponse courseErrorResponse;

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

                string jsn = JsonConvert.SerializeObject(createLeaveTypeModel);

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

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

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

                    courseResponse = JsonConvert.DeserializeObject <CourseResponse>(resultHostel);
                    icreateleavetype.sucess(courseResponse.message);
                }
                else
                {
                    UserDialogs.Instance.HideLoading();
                    string resultHostel = await response.Content.ReadAsStringAsync();

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