示例#1
0
        public IActionResult Get([FromQuery] string city, [FromQuery] int days)
        {
            using var scope = _logger.BeginScope("WeatherForecast Get {scopeInfo}", $"city={city}, days={days}");
            var weatherForecasts = _service.Get(city, days);

            return(Ok(weatherForecasts));
        }
示例#2
0
        public ObjectResult Get(string country, string city)
        {
            try
            {
                ILocation location = new Location {
                    Country = country, City = city
                };

                var result = _weatherService.Get(location);
                if (result.Result is WeatherInfo)
                {
                    WeatherInfo weatherInfo = (WeatherInfo)result.Result;
                    if (weatherInfo.Location.LocationId == 0)
                    {
                        string str = $"Cannot find country: {country} city: {city}";
                        return(StatusCode(404, new ErrorMessage {
                            error = str
                        }));
                    }
                    return(StatusCode(200, weatherInfo));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("ex: " + ex.Message);
            }
            return(StatusCode(500, new ErrorMessage {
                error = "Server error.  Please try again later."
            }));
        }
 public async Task <ActionResult> Get()
 {
     try
     {
         return(Ok(await _weatherService.Get()));
     }
     catch (Exception e)
     {
         return(BadRequest());
     }
 }
示例#4
0
        public async Task <IActionResult> GetWeather(string name)
        {
            var weather = await weatherService.Get(name);

            if (weather is null)
            {
                return(NotFound());
            }
            var response = mapper.Map <WeatherModel>(weather);

            return(Ok(response));
        }
        public async Task <IActionResult> Get(string city)
        {
            if (!string.IsNullOrEmpty(city))
            {
                var result = await _weatherService.Get(city);

                if (result != null)
                {
                    return(Ok(result));
                }
                else
                {
                    return(NotFound());
                }
            }

            return(Ok());
        }
示例#6
0
 public ActionResult Index(string city, int days)
 {
     if (!string.IsNullOrWhiteSpace(city))
     {
         Forecast forecast = weatherService.Get(city, days);
         Request  request  = new Request
         {
             RequestTown = forecast.city,
             RequestDays = days,
             RequestDate = forecast.GetDailyList()[0].date,
             RequestImg  = forecast.GetDailyList()[0].icon,
             RequestTemp = forecast.GetDailyList()[0].day
         };
         unitOfWork.Requests.Create(request);
         return(View(forecast));
     }
     return(View());
 }
        public async Task <ActionResult> Index(string city, int days)
        {
            var towns = await unitOfWork.Towns.GetAllAsync();

            ViewBag.Towns = towns;
            if (!string.IsNullOrWhiteSpace(city))
            {
                Forecast forecast = await weatherService.Get(city, days);

                Request request = new Request
                {
                    RequestTown = forecast.city,
                    RequestDays = days,
                    RequestDate = forecast.GetDailyList()[0].date,
                    RequestImg  = forecast.GetDailyList()[0].icon,
                    RequestTemp = forecast.GetDailyList()[0].day
                };
                await unitOfWork.Requests.CreateAsync(request);

                return(View(forecast));
            }
            return(View());
        }
 public async Task <IEnumerable <ForecastViewModel> > Get(int days)
 {
     return(await _service.Get(days));
 }
        public IEnumerable <WeatherForecast> Get()
        {
            List <WeatherForecast> list = _weatherService.Get();

            return(list);
        }
        public async Task <IActionResult> Index()
        {
            var model = await _weatherService.Get();

            return(View(model));
        }
示例#11
0
 public Task <IEnumerable <WeatherDataItem> > Get()
 {
     return(_weatherService.Get());
 }
示例#12
0
        private async Task SendWeather(WebSocket socket)
        {
            do
            {
                var message = new SocketMessage <string>
                {
                    MessageType = "Weather",
                    Payload     = JsonSerializer.Serialize <IEnumerable <WeatherForecast> >(_weatherService.Get())
                };

                await Send(message.ToJson(), socket);

                await Task.Delay(5000);
            } while (socket.State == WebSocketState.Open);
        }
 public IEnumerable <WeatherForecast> Get()
 {
     return(_weatherService.Get());
 }