async Task AddNewCar(Cars car) { await manager.SaveCarAsync(car); }
public async void OnSaveRoute(object sender, EventArgs e) { bool validation = false; if (!properties.ContainsKey("route")) { await DisplayAlert("Error", "Select points in map", "accept"); } else { if (string.IsNullOrEmpty((properties["route"] as Routes).From_Latitude) || string.IsNullOrEmpty((properties["route"] as Routes).To_Latitude)) { await DisplayAlert("Error", "Select points in map", "accept"); } else { if (string.IsNullOrEmpty(startingNameEntry.Text) || string.IsNullOrEmpty(endingNameEntry.Text) || string.IsNullOrEmpty(commentsEditor.Text)) { await DisplayAlert("Error", "fill blank fields", "accept"); } else { if (string.IsNullOrEmpty(seatsEntry.Text)) { await DisplayAlert("Error", "Seats can't be null", "accept"); } else { if (carPicker.SelectedIndex == -1) { await DisplayAlert("error", "select a car", "accept"); } else { validation = true; } } } } } if (validation == true) { newRoute = (Routes)properties["route"]; newRoute.From = startingNameEntry.Text; newRoute.To = endingNameEntry.Text; newRoute.Capacity = Int32.Parse("" + seatsEntry.Text); newRoute.Comments = commentsEditor.Text; newRoute.Depart_Time = departureTimePicker.Time.ToString(); newRoute.ID_User = currentUser.ID; DateTimeOffset dateRoute = new DateTimeOffset(departureDatePicker.Date.Add(departureTimePicker.Time)); newRoute.Depart_Date = dateRoute.DateTime; newRoute.Depart_Time = departureTimePicker.Time.ToString(); string carSelected = carPicker.Items.ElementAt(carPicker.SelectedIndex); Cars car = carsList.Where(cars => cars.Model + " " + cars.Color == carSelected).First(); newRoute.ID_Car = car.ID; activityIndicator.IsRunning = true; await routeManager.SaveRouteAsync(newRoute); activityIndicator.IsRunning = false; await DisplayAlert("Success", "Route added successfully", "Accept"); properties.Remove("route"); await Navigation.PopAsync(true); } }