private static void ReadMeasurements() { Console.WriteLine("Enter component id: "); string id = Console.ReadLine(); Console.WriteLine("Enter date: "); DateTime date; if (!DateTime.TryParse(Console.ReadLine(), out date)) { Console.Clear(); Console.WriteLine("Date not formated properly. Enter date in format mm/dd/yyyy"); return; } //DateTime date = DateTime.ParseExact(string.Format(Console.ReadLine(), "dd:mm:yyyy")); //15:09:2020 using (ShesDbContext context = new ShesDbContext()) { var list = context.Measurements.ToList(); var measList = list.Where(x => x.Component == id && x.TimeStamp.Date == date.Date).ToList(); Console.Clear(); Console.WriteLine("------------------------------------------------------------"); Console.WriteLine("Measurements for the selected date: "); measList.ForEach(x => Console.WriteLine($"{x.TimeStamp} - {x.Value}")); Console.WriteLine("------------------------------------------------------------"); } }
public SmartHomeEnergySystem(IWriteMeasurementToDb writer) { batteryObservers = new List <IObserver>(); consumerObservers = new List <IObserver>(); solarPanelObservers = new List <IObserver>(); using (ShesDbContext context = new ShesDbContext()) { foreach (Battery b in context.Batteries) { batteryObservers.Add(new BatteryWrapper(b, writer)); } foreach (Consumer c in context.Consumers) { consumerObservers.Add(new ConsumerWrapper(c, writer)); } foreach (SolarPanel sp in context.SolarPanels) { solarPanelObservers.Add(new SolarPanelWrapper(sp, writer)); } } }