public void Put([FromBody] WeatherForecastDTO model)
        {
            WeatherForecast existingForecast = _context.WeatherForecast.FirstOrDefault(w => w.Id == model.Id);

            if (existingForecast != null)
            {
                existingForecast.Date         = model.Date;
                existingForecast.Summary      = model.Summary;
                existingForecast.TemperatureC = model.TemperatureC;
                existingForecast.TemperatureF = model.TemperatureF;
                existingForecast.UserName     = model.UserName;
                _context.SaveChanges();
            }
        }
        public override async Task Execute(Message message, TelegramBotClient bot)
        {
            var chatId = message.Chat.Id;
            WeatherForecastDTO forecast = await GetForecast(message);

            StringBuilder messageBuilder = new StringBuilder();

            messageBuilder.AppendLine($"{roundPushpin} Current weather in <b>{forecast.Name}</b>");
            messageBuilder.AppendLine("");
            messageBuilder.AppendLine($"{GetEmojiByCode(forecast.Current.WeatherCondition.IconName)} <b>{forecast.Current.WeatherCondition.Name}</b>");
            messageBuilder.AppendLine($"{thermometer} <b>Temperature</b>: {Math.Round(forecast.Current.Temp, 1)}\u00B0C");
            messageBuilder.AppendLine($"{thermometer} <b>Feels like:</b> {Math.Round(forecast.Current.TempFeelsLike, 1)}\u00B0C");
            messageBuilder.AppendLine("");
            messageBuilder.AppendLine($"{dashing} <b>Wind:</b> {forecast.Current.WindSpeed} m/s");
            messageBuilder.AppendLine($"{leafFluttering} <b>Wind gust:</b> {forecast.Current.WindGust} m/s");
            messageBuilder.AppendLine($"{cyclone} <b>Pressure:</b> {forecast.Current.Pressure} hPa");
            messageBuilder.AppendLine($"{droplet} <b>Humidity:</b> {forecast.Current.Humidity}%");
            messageBuilder.AppendLine($"{telescope} <b>Visibility:</b> {forecast.Current.Visibility} m");
            messageBuilder.AppendLine($"{beachWithUmbrella} <b>UVI:</b> {forecast.Current.UVI}");
            messageBuilder.AppendLine("");
            messageBuilder.AppendLine($"{sunrise} <b>Sunrise:</b> {forecast.Current.SunriseDate}");
            messageBuilder.AppendLine($"{sunset} <b>Sunset:</b> {forecast.Current.SunsetDate}");
            messageBuilder.AppendLine("");
            messageBuilder.AppendLine($"{spiralCalendar} <b>Forecast date:</b> {forecast.Current.Date}");
            messageBuilder.AppendLine("");
            messageBuilder.AppendLine("Short daily forecast");

            int daysInShortForecast = 3;

            foreach (var dayForecast in forecast.Daily)
            {
                if (daysInShortForecast > 0)
                {
                    messageBuilder.AppendLine("");
                    messageBuilder.AppendLine($"{spiralCalendar} {dayForecast.Date.Date.ToString("dd.MM.yyyy")}");
                    messageBuilder.AppendLine($"{thermometer}{Math.Round(dayForecast.TempMin, 0)}-{Math.Round(dayForecast.TempMax, 0)}\u00B0C {GetEmojiByCode(dayForecast.WeatherCondition.IconName)}");
                    messageBuilder.AppendLine($"{dashing} {Math.Round(dayForecast.WindSpeed, 0)} m/s");
                    daysInShortForecast--;
                }
                else
                {
                    break;
                }
            }

            messageBuilder.AppendLine("");
            messageBuilder.AppendLine("For detailed daily forecast use command /daily_forecast");

            await bot.SendTextMessageAsync(chatId, messageBuilder.ToString(), parseMode : ParseMode.Html);
        }
Example #3
0
        public async Task <ActionResult <WeatherForecast> > Post([FromBody, BindRequired] WeatherForecastDTO weatherForecastDTO)
        {
            WeatherForecast weatherForecast = new WeatherForecast
            {
                Date         = DateTime.Now,
                TemperatureC = weatherForecastDTO.TemperatureC,
                Summary      = weatherForecastDTO.Summary
            };

            _context.WeatherForecast.Add(weatherForecast);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("Get", new { id = weatherForecast.Id }, weatherForecast));
        }
        public void Post([FromBody] WeatherForecastDTO model)
        {
            WeatherForecast weatheForecast = new WeatherForecast
            {
                Id           = model.Id,
                UserName     = model.UserName,
                Date         = model.Date,
                Summary      = model.Summary,
                TemperatureC = model.TemperatureC,
                TemperatureF = model.TemperatureF,
            };

            _context.Add(weatheForecast);
            _context.SaveChanges();
        }