public bool AddSolarPanel(SolarPanel solarPanel)
        {
            using (SHES_DBContext dbContext = new SHES_DBContext())
            {
                bool found = dbContext.SolarPanels.Any(s => s.SolarPanelID.Equals(solarPanel.SolarPanelID));
                if (found)
                {
                    return(false);
                }

                dbContext.SolarPanels.Add(solarPanel);
                dbContext.SaveChanges();

                return(true);
            }
        }
        public bool AddElecticVehicleCharger(ElectricVehicleCharger electricVehicleCharger)
        {
            using (SHES_DBContext dbContext = new SHES_DBContext())
            {
                bool found = dbContext.ElectricVehicleChargers.Any(evc => evc.BatteryID.Equals(electricVehicleCharger.BatteryID));
                if (found)
                {
                    return(false);
                }

                dbContext.ElectricVehicleChargers.Add(electricVehicleCharger);
                dbContext.SaveChanges();

                return(true);
            }
        }
        public bool AddBattery(Battery battery)
        {
            using (SHES_DBContext dbContext = new SHES_DBContext())
            {
                bool found = dbContext.Batteries.Any(b => b.BatteryID.Equals(battery.BatteryID));
                if (found)
                {
                    return(false);
                }

                dbContext.Batteries.Add(battery);
                dbContext.SaveChanges();

                return(true);
            }
        }
        public bool AddConsumer(Consumer consumer)
        {
            using (SHES_DBContext dbContext = new SHES_DBContext())
            {
                bool found = dbContext.Consumers.Any(c => c.ConsumerID.Equals(consumer.ConsumerID));
                if (found)
                {
                    return(false);
                }

                dbContext.Consumers.Add(consumer);
                dbContext.SaveChanges();

                return(true);
            }
        }
        public bool AddMeasurement(Measurement measurement)
        {
            using (SHES_DBContext dbContext = new SHES_DBContext())
            {
                bool found = dbContext.Measurements.Any(m => m.MesurementID.Equals(measurement.MesurementID));
                if (found)
                {
                    return(false);
                }

                dbContext.Measurements.Add(measurement);
                dbContext.SaveChanges();

                return(true);
            }
        }
        public bool RemoveElectricVehicleCharger(ElectricVehicleCharger evc)
        {
            using (SHES_DBContext dbContext = new SHES_DBContext())
            {
                bool found = dbContext.ElectricVehicleChargers.Any(e => e.BatteryID.Equals(evc.BatteryID));
                if (found)
                {
                    dbContext.ElectricVehicleChargers.Attach(evc);
                    dbContext.ElectricVehicleChargers.Remove(evc);
                    dbContext.SaveChanges();

                    return(true);
                }

                return(false);
            }
        }
        public bool RemoveSolarPanel(SolarPanel solarPanel)
        {
            using (SHES_DBContext dbContext = new SHES_DBContext())
            {
                bool found = dbContext.SolarPanels.Any(s => s.SolarPanelID.Equals(s.SolarPanelID));
                if (found)
                {
                    dbContext.SolarPanels.Attach(solarPanel);
                    dbContext.SolarPanels.Remove(solarPanel);
                    dbContext.SaveChanges();

                    return(true);
                }

                return(false);
            }
        }
        public bool UpdateSolarPanel(SolarPanel solarPanel)
        {
            using (SHES_DBContext dbContext = new SHES_DBContext())
            {
                bool found = dbContext.SolarPanels.Any(s => s.SolarPanelID.Equals(solarPanel.SolarPanelID));
                if (found)
                {
                    SolarPanel foundSolarPanel = dbContext.SolarPanels.SingleOrDefault(s => s.SolarPanelID.Equals(solarPanel.SolarPanelID));
                    dbContext.SolarPanels.Attach(foundSolarPanel);

                    foundSolarPanel.MaxPower = solarPanel.MaxPower;

                    dbContext.SaveChanges();

                    return(true);
                }

                return(false);
            }
        }
        public bool UpdateConsumer(Consumer consumer)
        {
            using (SHES_DBContext dbContext = new SHES_DBContext())
            {
                bool found = dbContext.Consumers.Any(c => c.ConsumerID.Equals(consumer.ConsumerID));
                if (found)
                {
                    Consumer foundConsumer = dbContext.Consumers.SingleOrDefault(c => c.ConsumerID.Equals(consumer.ConsumerID));
                    dbContext.Consumers.Attach(foundConsumer);

                    foundConsumer.Consumption = consumer.Consumption;
                    foundConsumer.IsConsuming = consumer.IsConsuming;

                    dbContext.SaveChanges();

                    return(true);
                }

                return(false);
            }
        }
        public bool UpdateBattery(Battery battery)
        {
            using (SHES_DBContext dbContext = new SHES_DBContext())
            {
                bool found = dbContext.Batteries.Any(b => b.BatteryID.Equals(battery.BatteryID));
                if (found)
                {
                    Battery foundBattery = dbContext.Batteries.SingleOrDefault(b => b.BatteryID.Equals(battery.BatteryID));
                    dbContext.Batteries.Attach(foundBattery);

                    foundBattery.MaxPower        = battery.MaxPower;
                    foundBattery.MaxCapacity     = battery.MaxCapacity;
                    foundBattery.CurrentCapacity = battery.CurrentCapacity;
                    foundBattery.Mode            = battery.Mode;

                    dbContext.SaveChanges();

                    return(true);
                }

                return(false);
            }
        }
        public bool UpdateElecticVehicleCharger(ElectricVehicleCharger electricVehicleCharger)
        {
            using (SHES_DBContext dbContext = new SHES_DBContext())
            {
                bool found = dbContext.ElectricVehicleChargers.Any(evc => evc.BatteryID.Equals(electricVehicleCharger.BatteryID));
                if (found)
                {
                    ElectricVehicleCharger foundEVC = dbContext.ElectricVehicleChargers.SingleOrDefault(evc => evc.BatteryID.Equals(electricVehicleCharger.BatteryID));
                    dbContext.ElectricVehicleChargers.Attach(foundEVC);

                    foundEVC.MaxPower        = electricVehicleCharger.MaxPower;
                    foundEVC.MaxCapacity     = electricVehicleCharger.MaxCapacity;
                    foundEVC.CurrentCapacity = electricVehicleCharger.CurrentCapacity;
                    foundEVC.Mode            = electricVehicleCharger.Mode;
                    foundEVC.OnCharger       = electricVehicleCharger.OnCharger;

                    dbContext.SaveChanges();

                    return(true);
                }

                return(false);
            }
        }