private async void AsyncDelete() { var answer = await App.Current.MainPage.DisplayAlert( Languages.Confirm, Languages.QuestionT, Languages.Yes, Languages.No); if (!answer) { return; } IsEnable = false; var url = App.Current.Resources["UrlAPI"].ToString(); var token = JsonConvert.DeserializeObject <TokenResponse>(Settings.Token); var response = await _apiService.DeleteAsync( url, "/api", "/Trips", Trip.Id, "bearer", token.Token); if (!response.IsSuccess) { IsEnable = true; await App.Current.MainPage.DisplayAlert(Languages.Error, response.Message, Languages.Accept); return; } IsEnable = true; await TripViewModel.GetInstance().UpdateUserData(); await Application.Current.MainPage.DisplayAlert("Trip Information", "Trips has been deleted", "Accept"); await Shell.Current.Navigation.PopToRootAsync(); }
private async void SaveAsync() { EntryEmpty = "Transparent"; var isValid = ValidateData(); if (!isValid) { return; } IsEnable = false; IsRunning = true; var url = App.Current.Resources["UrlAPI"].ToString(); var token = JsonConvert.DeserializeObject <TokenResponse>(Settings.Token); var traveler = JsonConvert.DeserializeObject <TravelerResponse>(Settings.Traveler); var tripRequest = new TripRequest { Id = Trip.Id, City = Trip.City, Budget = Trip.Budget, Date = Trip.Date, EndDate = Trip.EndDate, TravelerId = traveler.Id, }; Response <object> response; if (IsEdit) { response = await _apiService.PutAsync( url, "/api", "/Trips", tripRequest.Id, tripRequest, "bearer", token.Token); } else { response = await _apiService.PostAsync( url, "/api", "/Trips", tripRequest, "bearer", token.Token); } IsEnable = true; IsRunning = false; if (!response.IsSuccess) { await Application.Current.MainPage.DisplayAlert(Languages.Error, response.Message, Languages.Accept); return; } await TripViewModel.GetInstance().UpdateUserData(); await App.Current.MainPage.DisplayAlert( Languages.Accept, string.Format(Languages.CreateEditTripConfirm, IsEdit ? Languages.Edited : Languages.Created), Languages.Accept); await Shell.Current.Navigation.PopToRootAsync(); }
private async void SaveAsync() { EntryEmpty = "Transparent"; var isValid = ValidateData(); if (!isValid) { return; } IsEnable = false; IsRunning = true; var url = App.Current.Resources["UrlAPI"].ToString(); var token = JsonConvert.DeserializeObject <TokenResponse>(Settings.Token); var traveler = JsonConvert.DeserializeObject <TravelerResponse>(Settings.Traveler); var viaticRequest = new ViaticRequest { Id = Viatic.Id, Name = Viatic.Name, Description = Viatic.Description, InvoiceAmmount = Viatic.InvoiceAmmount, InvoiceDate = Viatic.InvoiceDate, ViaticType = SelectedViaticType.Name, TripId = TripIdNumber, TravelerId = traveler.Id, }; Response <object> response; if (IsEdit) { response = await _apiService.PutAsync( url, "/api", "/Viatics", viaticRequest.Id, viaticRequest, "bearer", token.Token); } else { response = await _apiService.PostAsync( url, "/api", "/Viatics", viaticRequest, "bearer", token.Token); } IsEnable = true; IsRunning = false; if (!response.IsSuccess) { await Application.Current.MainPage.DisplayAlert(Languages.Error, response.Message, Languages.Accept); return; } await App.Current.MainPage.DisplayAlert( Languages.TripEditCreation, string.Format(Languages.CreateEditTripConfirm, IsEdit ? Languages.Edited : Languages.Created), Languages.Accept); await Shell.Current.Navigation.PopAsync(); await TripViewModel.GetInstance().UpdateUserData(); }