예제 #1
0
        //public async Task<List<Store>> FindAllOffers(double storeOfferRadius)
        //{
        //    var stores = await GetStoresAsync(storeOfferRadius);

        //    foreach (var store in stores)
        //    {
        //        if(!_storeOfferFound.TryGetValue(store.Name, out var _))
        //        {
        //            _storeOfferFound.Add(store.Name, store);
        //        }
        //    }

        //    return stores;
        //}

        //public async Task<List<Store>> FindNewOffers(double storeOfferRadius)
        //{
        //    var stores = await GetStoresAsync(storeOfferRadius);

        //    var newStoreOffers = stores
        //        .Where(s => !_storeOfferFound.TryGetValue(s.Name, out var _))
        //        .ToList();

        //    newStoreOffers.ForEach(s => _storeOfferFound.Add(s.Name, s));

        //    return newStoreOffers;
        //}

        public async Task <List <Store> > GetAllStoresAsync()
        {
            var customerLocation = await _geoLocator.GetLocationAsync();

            if (customerLocation == null)
            {
                return(null);
            }

            var stores = await GetAsync <List <Store> >(ApiConstants.StoreEndpoint, CacheConstants.StoreCacheName);

            stores.ForEach(
                s => s.DistanceToCustomer = Math.Round(
                    Location.CalculateDistance(customerLocation, s.LocationLatitude, s.LocationLongitude, DistanceUnits.Kilometers), 2));

            return(stores);
        }
예제 #2
0
        private async void SetPropertiesAsync(IGeoLocator geoLocator)
        {
            UserLocation = await geoLocator.GetLocationAsync();

            Settings = await App.DataBase.GetSettingsAsync(1);
        }