// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, SensorInfoContext sensorInfoContext) { loggerFactory.AddConsole(); loggerFactory.AddDebug(); sensorInfoContext.EnsureSeedDataForContext(); app.UseStatusCodePages(); app.UseSwagger(); AutoMapper.Mapper.Initialize(cfg => { cfg.CreateMap <Entities.Sensor, Models.SensorWithoutLightDto>(); cfg.CreateMap <Entities.Sensor, Models.SensorDto>(); cfg.CreateMap <Entities.Light, Models.LightDto>(); cfg.CreateMap <Models.LightForCreationDto, Entities.Light>(); cfg.CreateMap <Models.SensorForCreationDto, Entities.Sensor>(); }); app.UseMvc(); }
public SensorInfoRepository(SensorInfoContext context) { _context = context; }
public DummyController(SensorInfoContext ctx) { _ctx = ctx; }
public static void EnsureSeedDataForContext(this SensorInfoContext context) { if (context.Sensors.Any()) { return; } var sensors = new List <Sensor>() { new Sensor() { Description = "Sensor 0.", Light = new List <Light>() { new Light() { Value = 10, TimeOfMeasurement = new DateTime(2019, 3, 19, 12, 0, 0), LightOn = false }, new Light() { Value = 20, TimeOfMeasurement = new DateTime(2019, 3, 19, 12, 5, 0), LightOn = false }, new Light() { Value = 30, TimeOfMeasurement = new DateTime(2019, 3, 19, 12, 10, 0), LightOn = false }, new Light() { Value = 40, TimeOfMeasurement = new DateTime(2019, 3, 19, 12, 15, 0), LightOn = false }, new Light() { Value = 30, TimeOfMeasurement = new DateTime(2019, 3, 19, 12, 20, 0), LightOn = false }, } }, new Sensor() { Description = "Sensor 1.", Light = new List <Light>() { new Light() { Value = 15, TimeOfMeasurement = new DateTime(2019, 3, 19, 12, 0, 0), LightOn = false }, new Light() { Value = 30, TimeOfMeasurement = new DateTime(2019, 3, 19, 12, 5, 0), LightOn = false }, new Light() { Value = 20, TimeOfMeasurement = new DateTime(2019, 3, 19, 12, 10, 0), LightOn = false }, new Light() { Value = 0, TimeOfMeasurement = new DateTime(2019, 3, 19, 12, 15, 0), LightOn = false }, new Light() { Value = 20, TimeOfMeasurement = new DateTime(2019, 3, 19, 12, 20, 0), LightOn = false }, } } }; context.Sensors.AddRange(sensors); context.SaveChanges(); }