public async Task <string> PostAsync([FromBody] SensorData data)
        {
            data.Optimize();

            await HubContext.Clients.All.SendAsync("PushSensorData", data);

            using (appDB)
            {
                SensorDataRepository Srepo = new SensorDataRepository(appDB);
                await Srepo.InsertAsync(data);

                if (data.SoilMoisture > 50)
                {
                    Models.Action act = new Models.Action()
                    {
                        Text = "Farm will need water soon ",
                        Act  = 4
                    };

                    if (data.SoilMoisture > 70)
                    {
                        act.Text = "farm needs watering ";
                        act.Act  = 3;
                    }
                    ActionRepository repo = new ActionRepository(appDB);
                    await repo.InsertAsync(act);
                }
            }

            return("OK");
        }
        public async Task <string> PostMoistureAsync(double value)
        {
            var val = value / 10;
            await HubContext.Clients.All.SendAsync("PushSoilSensorData", val);

            if (val > 50)
            {
                using (appDB)
                {
                    Models.Action act = new Models.Action()
                    {
                        Text = "Farm will need water soon ",
                        Act  = 4
                    };

                    if (val > 70)
                    {
                        act.Text = "farm needs watering ";
                        act.Act  = 3;
                    }
                    ActionRepository repo = new ActionRepository(appDB);
                    await repo.InsertAsync(act);
                }
            }
            return("OK");
        }
        public async Task <List <Condition> > GetForecastAsync()
        {
            WeatherFacade    weatherFacade = new WeatherFacade(API.Value);
            List <Condition> weather       = new List <Condition>();

            using (appDB){
                WeatherRepository repo = new WeatherRepository(appDB);
                weather = await repo.LatestConditionAsync(true);

                if (weather.Count > 0)
                {
                    var      con  = weather[0];
                    TimeSpan span = (DateTime.Now - con.timeStamp);
                    if (span.Minutes < 30)
                    {
                        Console.WriteLine("db");
                        //myList.OrderBy(x => x.Created).ToList();
                        return(weather.OrderBy(x => x.date).ToList());
                    }
                }
                Console.WriteLine("api");
                var w = weatherFacade.GetForecast();
                if (w != null)
                {
                    await repo.InsertAsync(w, true);

                    weather = w;
                }

                var wa = weather.Where(c => c.weather.Trim() == "Rain").First();
                if (wa != null)
                {
                    IOT.Models.Action act = new IOT.Models.Action()
                    {
                        Text = "Weather forecast predicts " + wa.description + " on " + wa.date,
                        Act  = 0
                    };

                    ActionRepository repo2 = new ActionRepository(appDB);
                    await repo2.InsertAsync(act);
                }
            }
            return(weather.OrderBy(x => x.date).ToList());;
        }