private async void DeleteRoute() { var answer = await Application.Current.MainPage.DisplayAlert( Languages.ConfirmDeleteRoute, Languages.DeleteRouteConfirmation, Languages.Yes, Languages.No); if (!answer) { return; } var connection = await this.apiService.CheckConnection(); if (!connection.IsSuccess) { await Application.Current.MainPage.DisplayAlert( Languages.Error, connection.Message, Languages.AcceptDisplay); return; } var url = Application.Current.Resources["APIMovilidad"].ToString(); var prefix = Application.Current.Resources["APIprefix"].ToString(); var controller = Application.Current.Resources["RoutesController"].ToString(); var response = await this.apiService.DeleteAsync(url, prefix, controller, this.RouteView.RouteId, Settings.TokenType, Settings.AccessToken); if (!response.IsSuccess) { await Application.Current.MainPage.DisplayAlert( Languages.Error, response.Message, Languages.AcceptDisplay); return; } var routesViewModel = RoutesViewModel.GetInstance(); var deletedRoute = routesViewModel.MyRoutes.Where(p => p.RouteId == this.RouteView.RouteId).FirstOrDefault(); if (deletedRoute != null) { routesViewModel.MyRoutes.Remove(deletedRoute); } routesViewModel.RefreshList(); await App.Navigator.PopAsync(); }
private async void SaveRoute() { if (string.IsNullOrEmpty(this.NumOfSeats.ToString())) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.NumOfSeatValidation, Languages.AcceptDisplay); return; } if (this.NumOfSeats < 1) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.NumOfSeatMinValidation, Languages.AcceptDisplay); return; } if (this.OriginCity == null) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.OriginCityValidation, Languages.AcceptDisplay); return; } if (this.DestinyCity == null) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.DestinyCityValidation, Languages.AcceptDisplay); return; } if (this.DestinyCity.CityId == this.OriginCity.CityId) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.OriginDestinyCityValidation, Languages.AcceptDisplay); return; } if (this.Date == null) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.DateValidation, Languages.AcceptDisplay); return; } if (this.Time == null) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.TimeValidation, Languages.AcceptDisplay); return; } this.IsRunning = true; this.IsEnable = false; var connection = await this.apiService.CheckConnection(); if (!connection.IsSuccess) { this.IsRunning = false; this.IsEnable = true; await Application.Current.MainPage.DisplayAlert(Languages.Error, connection.Message, Languages.AcceptDisplay); return; } var dateline = Date.Date; var fullDate = new DateTime(dateline.Year, dateline.Month, dateline.Day, Time.Hours, Time.Minutes, Time.Seconds); byte[] imageArray = null; if (this.file != null) { imageArray = FilesHelper.ReadFully(this.file.GetStream()); } var route = new Route() { NumSeats = this.NumOfSeats.ToString(), OriginID = this.OriginCity.CityId, DestinyID = this.DestinyCity.CityId, Description = this.Description, Date = fullDate, UserId = MainViewModel.GetInstance().UserASP.Id, IsDeleted = false, Inbackend = false, ImageArray = imageArray }; var url = Application.Current.Resources["APIMovilidad"].ToString(); var prefix = Application.Current.Resources["APIprefix"].ToString(); var controller = Application.Current.Resources["RoutesController"].ToString(); var response = await this.apiService.PostAsync(url, prefix, controller, route, Settings.TokenType, Settings.AccessToken); if (!response.IsSuccess) { this.IsRunning = false; this.IsEnable = true; await Application.Current.MainPage.DisplayAlert(Languages.Error, response.Message, Languages.AcceptDisplay); return; } this.IsRunning = false; this.IsEnable = true; var routesVM = RoutesViewModel.GetInstance(); routesVM.MyRoutes.Add((Route)response.Result); routesVM.RefreshList(); await App.Navigator.PopAsync(); }