async private void SaveButton_Clicked(object sender, EventArgs e) { //await DisplayAlert("Info", ImagePathTemp, "OK"); //return; if (string.IsNullOrWhiteSpace(entryPlacas.Text) || string.IsNullOrWhiteSpace(entryMarca.Text) || string.IsNullOrWhiteSpace(entryModelo.Text) || ColorPicker.SelectedIndex == -1 || CityPicker.SelectedIndex == -1) { await DisplayAlert("Error", "Todos los datos son obligatorios", "OK"); return; } Car car = new Car { Placas = entryPlacas.Text, Marca = entryMarca.Text, Modelo = Convert.ToInt32(entryModelo.Text), Color = ColorPicker.SelectedItem.ToString(), Foto = ImagePathTemp, Estado = CityPicker.SelectedItem.ToString(), Alias = entryAlias.Text, UserId = (Application.Current as App).UserData.Id }; try { int saved = await CarHelper.SaveItemAsync(car); await DisplayAlert("Guardar", "¡Coche guardado correctamente!", "OK"); await Navigation.PopAsync(); } catch (Exception) { await DisplayAlert("Error", "Hubo un error verifique con el Administrador", "OK"); return; } }
async private void ToolbarItem_Clicked(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(placasEntry.Text) || string.IsNullOrWhiteSpace(marcaEntry.Text) || string.IsNullOrWhiteSpace(modeloEntry.Text) || string.IsNullOrWhiteSpace(aliasEntry.Text) || estadosPicker.SelectedIndex == -1 || colorPicker.SelectedIndex == -1 || string.IsNullOrWhiteSpace(ImagePath)) { await DisplayAlert("Error", "Todos los campos son obligatorios", "OK"); return; } Car car = new Car { Placas = placasEntry.Text, Marca = marcaEntry.Text, Modelo = Convert.ToInt32(modeloEntry.Text), Alias = aliasEntry.Text, Estado = estadosPicker.SelectedItem.ToString(), Color = colorPicker.SelectedItem.ToString(), Foto = ImagePath, UserId = user.Id }; try { await CarHelper.SaveItemAsync(car); await DisplayAlert("Guardar", "Coche agregado correctamente", "OK"); await Navigation.PopAsync(); } catch (Exception) { await DisplayAlert("Error", "Hubo un error y el coche no se agrego a la base de datos", "OK"); return; } }