Beispiel #1
0
        public JObject SetVoltage([FromBody] BatteryInformation battery)
        {
            try
            {
                var context = new DatabaseContext();
                context.Batteries.Add(new Battery()
                {
                    BatteryId = context.Settings.Find(Int32.Parse(ConfigurationManager.AppSettings.Get("Battery"))).Value, Voltage = (float)battery.Voltage, DateTime = DateTime.Now
                });
                context.SaveChanges();

                var informationSend = context.Settings.Find(Int32.Parse(ConfigurationManager.AppSettings.Get("BatteryInformationSend")));
                if (informationSend.Value != null && battery.Voltage > 12)
                {
                    informationSend.Value = null;
                    context.SaveChanges();
                }
                if (informationSend.Value == null && battery.Voltage < 11.5)
                {
                    var ib = new InformationBroker();
                    ib.SendSms(InformationBroker.BatteryLow);
                    informationSend.Value = "Mega";
                    context.SaveChanges();
                }
                var value = "{ \"response\": \"success\" }";
                return(JObject.Parse(value));
            }
            catch (Exception e)
            {
                var value = "{ \"response\": \"error " + e.Message + "\" }";
                return(JObject.Parse(value));
            }
        }
Beispiel #2
0
        public JObject DailyStatus()
        {
            var context       = new DatabaseContext();
            var latestBattery = context.Batteries.OrderByDescending(x => x.Id).FirstOrDefault();
            var ib            = new InformationBroker();

            if (DateTime.Now.Hour < 12)
            {
                ib.SendSms(InformationBroker.MorningBattery, latestBattery.Voltage);
            }
            else
            {
                ib.SendSms(InformationBroker.EveningBattery, latestBattery.Voltage);
            }
            var value = "{ \"response\": \"messageSend\" }";

            return(JObject.Parse(value));
        }