Beispiel #1
0
        public void SaveSilo(Model.Silo record, int bassinid)
        {
            using (Ringsted1Entities111 context = new Ringsted1Entities111())
            {
                Silo query = (from o in context.Silos
                              where o.BassinID == record.BassinID
                              select o).FirstOrDefault();

                if (query == null)
                {
                    Silo siloE = new Silo();
                    siloE.BassinID   = bassinid;
                    siloE.FoodAmount = record.FoodAmount;
                    context.Silos.Add(siloE);
                    try
                    {
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        LoggerSingleton.Instance.Log("An exception occurred when attempting to save a new silo to the database: ", ex);
                    }
                }
            }
        }
Beispiel #2
0
        public void SaveSensor(Model.Sensor record)
        {
            using (Ringsted1Entities111 context = new Ringsted1Entities111())
            {
                Sensor query = (from o in context.Sensors
                                where o.BassinID == record.BassinID
                                select o).FirstOrDefault();

                if (query == null)
                {
                    Sensor sensorE = new Sensor();
                    sensorE.BassinID  = record.BassinID;
                    sensorE.IPAddress = record.IP;
                    context.Sensors.Add(sensorE);
                    try
                    {
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        LoggerSingleton.Instance.Log("An exception occurred when attempting to save a new sensor to the database: ", ex);
                    }
                }
            }
        }
Beispiel #3
0
        public void SaveHall(Model.Hall record)
        {
            using (Ringsted1Entities111 context = new Ringsted1Entities111())
            {
                Hall query = (from o in context.Halls
                              where o.Name == record.Name
                              select o).FirstOrDefault();

                //hall wasn't found in the database - create one
                if (query == null)
                {
                    Hall hallE = new Hall();
                    hallE.Name = record.Name;
                    context.Halls.Add(hallE);
                    try
                    {
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        LoggerSingleton.Instance.Log("An exception occurred when attempting to save a new hall to the database: ", ex);
                    }
                }
            }
        }
Beispiel #4
0
        public void SaveWarning(Model.Warning record)
        {
            using (Ringsted1Entities111 context = new Ringsted1Entities111())
            {
                Warning query = (from o in context.Warnings
                                 where o.ID == 1
                                 select o).FirstOrDefault();

                if (query == null)
                {
                    Warning warningE = new Warning();
                    warningE.Priority = record.Priority;
                    warningE.Message  = record.Message;
                    context.Warnings.Add(warningE);
                    try
                    {
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        LoggerSingleton.Instance.Log("An exception occurred when attempting to save a new warning to the database: ", ex);
                    }
                }
            }
        }
Beispiel #5
0
        public void SaveSensorData(Model.SensorData record)
        {
            using (Ringsted1Entities111 context = new Ringsted1Entities111())
            {
                SensorData query = (from o in context.SensorDatas
                                    where o.SensorID == record.SensorID
                                    select o).FirstOrDefault();

                if (query != null)
                {
                    SensorData sensorDataE = new SensorData();
                    sensorDataE.SensorID           = record.SensorID;
                    sensorDataE.AmbientTemperature = record.AmbientTemperature;
                    sensorDataE.WaterLevel         = record.WaterLevel;
                    sensorDataE.WindSpeed          = record.WindSpeed;
                    sensorDataE.WaterTemperature   = record.WaterTemperature;
                    context.SensorDatas.Add(sensorDataE);
                    try
                    {
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        LoggerSingleton.Instance.Log("An exception occurred when attempting to save sensordata to the database: ", ex);
                    }
                }
                else
                {
                    // test code - remember to remove this
                    SensorData sensorDataE = new SensorData();
                    sensorDataE.SensorID           = record.SensorID;
                    sensorDataE.AmbientTemperature = record.AmbientTemperature;
                    sensorDataE.WaterLevel         = record.WaterLevel;
                    sensorDataE.WindSpeed          = record.WindSpeed;
                    sensorDataE.WaterTemperature   = record.WaterTemperature;
                    context.SensorDatas.Add(sensorDataE);
                    try
                    {
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        LoggerSingleton.Instance.Log("An exception occurred when attempting to save sensordata to the database: ", ex);
                    }
                }
            }
        }
Beispiel #6
0
        public void SaveTrigger(Model.Trigger record, byte bassinid, byte warningid)
        {
            using (Ringsted1Entities111 context = new Ringsted1Entities111())
            {
                Trigger query = (from o in context.Triggers
                                 where o.BassinID == bassinid
                                 select o).FirstOrDefault();

                if (query != null)
                {
                    // fix this, this db insert exception
                    Trigger triggerE = new Trigger();
                    triggerE.DateTime  = DateTime.Now;
                    triggerE.BassinID  = bassinid;
                    triggerE.WarningID = warningid;
                    context.Triggers.Add(triggerE);
                    try
                    {
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        LoggerSingleton.Instance.Log("An exception occurred when attempting to save a new trigger to the database: ", ex);
                    }
                }
                //else
                //{
                //    // TODO - test this
                //    Trigger triggerE = new Trigger();
                //    triggerE.DateTime = DateTime.Now;
                //    triggerE.WarningID = record.WarningID;
                //    triggerE.BassinID = record.BassinID;
                //    context.Triggers.Add(triggerE);
                //    try
                //    {
                //        context.SaveChanges();
                //    }
                //    catch (Exception ex)
                //    {
                //        LoggerSingleton.Instance.Log("An exception occurred when attempting to save a trigger to the database: ", ex);
                //    }
                //}
            }
        }
Beispiel #7
0
        public void SaveBassin(Model.Bassin record, int hallid)
        {
            using (Ringsted1Entities111 context = new Ringsted1Entities111())
            {
                Bassin query = (from o in context.Bassins
                                where o.HallID == record.HallID
                                select o).FirstOrDefault();

                if (query == null)
                {
                    Bassin bassinE = new Bassin();
                    bassinE.HallID = hallid;
                    context.Bassins.Add(bassinE);
                    try
                    {
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        LoggerSingleton.Instance.Log("An exception occurred when attempting to save a new bassin to the database: ", ex);
                    }
                }
            }
        }