// GET api/barcode
        public async Task<List<Beer>> Get(string upc)
        {
            try
            {
                var beers = new List<Beer>();
                foreach(var b in context.Beers)
                {
                    foreach(var barcode in b.Upcs)
                    {
                        if (barcode == upc)
                            beers.Add(b);
                    }
                }
                if(beers.Count > 0)
                    return beers;

                var properties = new Dictionary<string, string>();
                properties.Add("UPC", upc);
                telemetryClient.TrackEvent("LookupBarcode", properties);

                var rateBeerClient = new RateBeer.Client();
                var results = await rateBeerClient.SearchForBeer(upc);
                if (results == null)
                    return null;

                var breweryDbService = new Services.BreweryDBService();
                return await breweryDbService.SearchBeers(results.BeerName);
            }
            catch(Exception ex)
            {
                telemetryClient.TrackException(ex);
                return null;
            }
        }
Ejemplo n.º 2
0
        async public void LookupUPC()
        {
            var client = new RateBeer.Client();
            var beerInfo = await client.SearchForBeer("5411681014005");

            if (beerInfo.BeerName == "Duvel")
                Assert.Pass();
            else
                Assert.Fail();
        }
Ejemplo n.º 3
0
        async public void LookupUPC()
        {
            var client   = new RateBeer.Client();
            var beerInfo = await client.SearchForBeer("5411681014005");

            if (beerInfo.BeerName == "Duvel")
            {
                Assert.Pass();
            }
            else
            {
                Assert.Fail();
            }
        }
Ejemplo n.º 4
0
        // GET api/barcode
        public async Task <List <Beer> > Get(string upc)
        {
            try
            {
                var beers = new List <Beer>();
                foreach (var b in context.Beers)
                {
                    foreach (var barcode in b.Upcs)
                    {
                        if (barcode == upc)
                        {
                            beers.Add(b);
                        }
                    }
                }
                if (beers.Count > 0)
                {
                    return(beers);
                }

                var properties = new Dictionary <string, string>();
                properties.Add("UPC", upc);
                telemetryClient.TrackEvent("LookupBarcode", properties);

                var rateBeerClient = new RateBeer.Client();
                var results        = await rateBeerClient.SearchForBeer(upc);

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

                var breweryDbService = new Services.BreweryDBService();
                return(await breweryDbService.SearchBeers(results.BeerName));
            }
            catch (Exception ex)
            {
                telemetryClient.TrackException(ex);
                return(null);
            }
        }
Ejemplo n.º 5
0
        async void ScanBarcode()
        {
           try
            {
                var scanner = new ZXing.Mobile.MobileBarcodeScanner(this);
                var result =  await scanner.Scan();

                UserDialogs.Instance.ShowLoading("Searching for beer");
                upc = result.Text;
                var client = new RateBeer.Client();
                var response = await client.SearchForBeer(upc);

                if(response != null)
                {
                    rateBeerId = response.BeerID;
                    searchBar.Text = response.BeerName;
                    searchBar.BecomeFirstResponder();
                    UserDialogs.Instance.HideLoading();

                    Insights.Track("User searched with barcode", new Dictionary<string, string> {
                        {"Beer Name", response.BeerName},
                        {"Beer UPC", result.Text}
                    });
                }
                else
                {
                    UserDialogs.Instance.ShowError("Unable to find beer with that barcode :(");
                }

            }
            catch (Exception ex)
            {
                Xamarin.Insights.Report(ex);
            }
        }