Beispiel #1
0
 public void AddRating(BarData barData, int rating)
 {
     if (barData == null)
     {
         throw new ArgumentNullException(nameof(barData), "BarRating.AddRating null parameter");
     }
     WebApiAccess.SaveBarRating(barData, rating);
 }
Beispiel #2
0
        private void ManualBarRating_Click(object sender, EventArgs e)
        {
            var rating = manualBarRating.Rating;
            int ratingNumber;

            if (_selectedBar != null && rating != "" && int.TryParse(rating, out ratingNumber))
            {
                Task.Run(() => _barRating.AddRating(_selectedBar, ratingNumber)).Wait();
                Task.Run(() => _selectedBar.Ratings = WebApiAccess.GetBarRatings(_selectedBar)).Wait();
                Resort();
            }
        }
Beispiel #3
0
        private async void GoButton_Click(object sender, EventArgs e)
        {
            var latitude  = GetLatitude();
            var longitude = GetLongitude();
            var radius    = GetRadius();
            var failedToConnectCounter = 0;
            var providerCount          = _providerList.Count;

            try
            {
                var barsFromProvider = new List <BarData>();
                var progressStep     = 100 / providerCount;
                var result           = new BarDataModel();

                var currentProgressValue = 0;
                GoButton.Enabled = false;
                InitiateProgressBars();
                UpdateProgressBars(currentProgressValue);
                foreach (IBeerable provider in _providerList)
                {
                    try
                    {
                        barsFromProvider = await CollectBarsFromProvider(provider, latitude, longitude, radius);
                    }
                    catch (HttpRequestException)
                    {
                        if (++failedToConnectCounter == providerCount)
                        {
                            MessageBox.Show("Check your internet connection, it seems to be down.");
                        }
                    }
                    catch (WebException)
                    {
                        MessageBox.Show("Failed connecting to: " + provider.ProviderName);
                    }

                    result.AddRange(barsFromProvider);
                    currentProgressValue += progressStep;
                    UpdateProgressBars(currentProgressValue);
                }
                result.RemoveDuplicates();
                result.RemoveBarsOutsideRadius(radius);
                await Task.Run(() => result = (BarDataModel)WebApiAccess.GetAllBarData(result));

                HideProgressBars();

                // Display
                _barRating.BarsData = result;
                var currentLocation = GetCurrentLocation();
                if (result != null)
                {
                    foreach (var bar in _barRating.BarsData)
                    {
                        bar.DistanceToCurrentLocation =
                            currentLocation.GetDistanceTo(new GeoCoordinate(bar.Latitude, bar.Longitude));
                    }
                    SortList(CompareType.Distance);
                }
            }
            catch (ArgumentsForProvidersException)
            {
                MessageBox.Show("Please enter the required data correctly. Erroneus data is painted red.");
            }
            finally
            {
                HideProgressBars();
                GoButton.Enabled = true;
            }
        }