public void OnGet()
 {
     using (WebClient webClient = new WebClient())
     {
         string             breweryData = webClient.DownloadString("https://breweryratings20191109050130.azurewebsites.net/Privacy");
         List <BreweryData> Breweries   = BreweryData.FromJson(breweryData);
         ViewData["Breweries"] = Breweries;
     }
 }
Exemplo n.º 2
0
        public bool Update(int id, BreweryData breweryData)
        {
            bool isUpdated = breweryRepository.Update(id, new Demo_API_BeerAPI.DAL.Entities.BreweryEntity()
            {
                Name        = breweryData.Name,
                Headquarter = breweryData.Headquarter,
                Country     = breweryData.Country
            });

            return(isUpdated);
        }
Exemplo n.º 3
0
        public int Add(BreweryData breweryData)
        {
            int newId = breweryRepository.Insert(new Demo_API_BeerAPI.DAL.Entities.BreweryEntity()
            {
                Name        = breweryData.Name,
                Headquarter = breweryData.Headquarter,
                Country     = breweryData.Country
            });

            return(newId);
        }
Exemplo n.º 4
0
        public IHttpActionResult AddNewBrewery([FromBody] BreweryData data)
        {
            if (data is null || !ModelState.IsValid)
            {
                return(BadRequest("Data is required !"));
            }

            if (BreweryService.Instance.Exists(data.Name))
            {
                return(BadRequest($"The brewery {data.Name} does already exists"));
            }

            int newId = BreweryService.Instance.Add(data);

            Brewery brewery = BreweryService.Instance.GetOne(newId);

            return(Json(brewery));
        }
Exemplo n.º 5
0
        public IHttpActionResult UpdateBrewery(int id, [FromBody] BreweryData data)
        {
            if (data is null || !ModelState.IsValid)
            {
                return(BadRequest("Data is required !"));
            }

            if (BreweryService.Instance.GetOne(id) is null)
            {
                return(BadRequest($"The brewery {id} does not exists"));
            }

            bool isUpdated = BreweryService.Instance.Update(id, data);

            if (isUpdated)
            {
                Brewery brewery = BreweryService.Instance.GetOne(id);
                return(Json(brewery));
            }
            else
            {
                return(BadRequest("An error occurred during the request"));
            }
        }
Exemplo n.º 6
0
        public BrewerySearchResults breweriesByLocation(String lat = null, String lon = null, String radius = "10", string city = null, String state = null, String zip = null)
        {
            try
            {
                String urlParameters = "&withSocialAccounts=Y&unit=mi";
                urlParameters += "&radius=" + radius;
                if (lat != null)
                {
                    urlParameters += "&lat=" + lat;
                }
                if (lon != null)
                {
                    urlParameters += "&lng=" + lon;
                }
                if (city != null)
                {
                    urlParameters += "&locality=" + city;
                }
                if (state != null)
                {
                    urlParameters += "&region=" + state;
                }
                if (zip != null)
                {
                    urlParameters += "&postalCode=" + zip;
                }

                // http://api.brewerydb.com/v2/breweries?key=8ee12a2f196eb183914740dbbb5ccfff&name=The%20Alchemist%20&withLocations=Y&hasImages=Y
                HttpClient httpClient = new HttpClient();
                httpClient.BaseAddress = new Uri(breweryDbBaseUrl);
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = httpClient.GetAsync("search/geo/point?key=" + breweryDbApiKey + urlParameters).Result;
                if (response.IsSuccessStatusCode)
                {
                    // Parse the response body. Blocking!
                    var dataObject = response.Content.ReadAsAsync <BreweryLocationSearchResults>().Result;
                    BrewerySearchResults brewerySearchResults = new BrewerySearchResults();
                    brewerySearchResults.currentPage   = dataObject.currentPage;
                    brewerySearchResults.numberOfPages = dataObject.numberOfPages;
                    brewerySearchResults.totalResults  = dataObject.totalResults;
                    brewerySearchResults.data          = new List <BreweryData>();

                    // Iterate through the data object and build a BrewerySearchResults data object
                    for (int x = 0; x < dataObject.totalResults; x++)
                    {
                        // For each brewery location returned, transform to a standard BrewerySearchResults object
                        BreweryLocationData breweryLocationData = dataObject.data[x];

                        //BreweryData breweryData = breweryLocationData.brewery;
                        BreweryData breweryData = new BreweryData();
                        breweryData.id               = breweryLocationData.id;
                        breweryData.name             = breweryLocationData.brewery.name;
                        breweryData.description      = breweryLocationData.brewery.description;
                        breweryData.nameShortDisplay = breweryLocationData.brewery.nameShortDisplay;
                        breweryData.website          = breweryLocationData.brewery.website;
                        breweryData.established      = breweryLocationData.brewery.established;
                        breweryData.isOrganic        = breweryLocationData.brewery.isOrganic;
                        breweryData.images           = breweryLocationData.brewery.images;
                        breweryData.status           = breweryLocationData.brewery.status;
                        breweryData.statusDisplay    = breweryLocationData.brewery.statusDisplay;
                        breweryData.createDate       = breweryLocationData.brewery.createDate;
                        breweryData.updateDate       = breweryLocationData.brewery.updateDate;
                        var breweryLocation = new BreweryLocation();
                        breweryLocation.latitude            = breweryLocationData.latitude;
                        breweryLocation.longitude           = breweryLocationData.longitude;
                        breweryLocation.isPrimary           = breweryLocationData.isPrimary;
                        breweryLocation.name                = breweryLocationData.name;
                        breweryLocation.streetAddress       = breweryLocationData.streetAddress;
                        breweryLocation.locationTypeDisplay = breweryLocationData.locationTypeDisplay;
                        breweryLocation.locationType        = breweryLocationData.locationType;
                        breweryLocation.locality            = breweryLocationData.locality;
                        breweryLocation.region              = breweryLocationData.region;
                        breweryLocation.postalCode          = breweryLocationData.postalCode;
                        breweryData.locations               = new List <BreweryLocation>();
                        breweryData.locations.Add(breweryLocation);
                        brewerySearchResults.data.Add(breweryData);
                    }
                    return(brewerySearchResults);
                }
                else
                {
                    throw new Exception("Error retrieving results");
                };
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.InnerException);
                throw e;
            }
        }