Пример #1
0
        public ActionResult Get()
        {
            try
            {
                GeoLookupService geoLookupService = new GeoLookupService();
                string           result           = string.Empty;

                var city   = geoLookupService.GetCityForZipCode(zipCode);
                var state  = geoLookupService.GetStateForZipCode(zipCode);
                var coords = geoLookupService.GetCoordinatesForZipCode(zipCode);

                WeatherService weatherService = new WeatherService();
                var            farenheit      = weatherService.GetTempFarenheit(coords.Latitude, coords.Longitude);

                EnglishMetricConverter englishMetricConverter = new EnglishMetricConverter();
                var celcius = englishMetricConverter.FarenheitToCelcious(farenheit);

                result = $"The current temperature is {farenheit.ToString("F1")}F/{celcius.ToString("F1")}C in {city}, {state}";
                return(Ok(result));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Пример #2
0
        public LocalTemperature GetTemperature(string zipCode)
        {
            var coords = _geoLookupService.GetCoordinatesForZipCode(zipCode);
            var city   = _geoLookupService.GetCityForZipCode(zipCode);
            var state  = _geoLookupService.GetStateForZipCode(zipCode);

            var farenheit = _weatherService.GetTempFarenheit(coords.Latitude, coords.Longitude);
            var celcius   = _englishMetricConverter.FarenheitToCelcious(farenheit);

            return(new LocalTemperature()
            {
                Farenheit = farenheit, Celcius = celcius, City = city, State = state
            });
        }
Пример #3
0
        private static void CallingMethod(string[] args)
        {
            const string zipCode = "83714";

            GeoLookupService geoLookupService = new GeoLookupService();

            var city   = geoLookupService.GetCityForZipCode(zipCode);
            var state  = geoLookupService.GetStateForZipCode(zipCode);
            var coords = geoLookupService.GetCoordinatesForZipCode(zipCode);

            WeatherService weatherService = new WeatherService();
            var            farenheit      = weatherService.GetTempFarenheit(coords.Latitude, coords.Longitude);

            EnglishMetricConverter englishMetricConverter = new EnglishMetricConverter();
            var celcius = englishMetricConverter.FarenheitToCelcious(farenheit);

            Console.WriteLine("The current temperature is {0}F/{1}C. in {2}, {3}",
                              farenheit.ToString("F1"),
                              celcius.ToString("F1"),
                              city,
                              state);
        }