public LocationDetailViewModel(FavouriteDataTable currentAddress) { CurrentAddress = currentAddress; if (currentAddress != null) { Title = CurrentAddress.CountryName; } AddFavoriteCommand = new Command(async() => await AddFavoriteCommandExecution()); }
public Task <int> SaveItemAsync(FavouriteDataTable item) { if (item.PK != 0) { return(database.UpdateAsync(item)); } else { return(database.InsertAsync(item)); } }
public async Task GetCurrentLocation() { try { var hasPermission = await Utils.CheckPermissions(Permission.Location); if (!hasPermission) { return; } var locator = CrossGeolocator.Current; using (UserDialogs.Instance.Loading("Get Current Location..", null, null, true, MaskType.Black)) { var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(5000)); if (position == null) { return; } var addresses = await locator.GetAddressesForPositionAsync(position); CurrentAddress = new FavouriteDataTable(); var items = addresses.GetEnumerator(); while (items.MoveNext()) { var current = items.Current; CurrentAddress.AdminArea = current.AdminArea; CurrentAddress.CountryCode = current.CountryCode; CurrentAddress.CountryName = current.CountryName; CurrentAddress.FeatureName = current.FeatureName; CurrentAddress.Latitude = current.Latitude; CurrentAddress.Locality = current.Locality; CurrentAddress.Longitude = current.Longitude; CurrentAddress.PostalCode = current.PostalCode; CurrentAddress.SubAdminArea = current.SubAdminArea; CurrentAddress.SubLocality = current.SubLocality; CurrentAddress.SubThoroughfare = current.SubThoroughfare; CurrentAddress.Thoroughfare = current.Thoroughfare; break; } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
public LocationDetailView(FavouriteDataTable CurrentAddress, bool isfav = false) { InitializeComponent(); if (!isfav) { ToolbarItem toolbarItem = new ToolbarItem(); toolbarItem.Text = "Favourite"; toolbarItem.SetBinding(ToolbarItem.CommandProperty, "AddFavoriteCommand"); this.ToolbarItems.Add(toolbarItem); } ldvm = new LocationDetailViewModel(CurrentAddress); BindingContext = ldvm; ldvm.BaseNavigation = Navigation; }
public Task <int> DeleteItemAsync(FavouriteDataTable item) { return(database.DeleteAsync(item)); }