// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); }); // Add framework services. services.AddOptions(); services.Configure <MeasurementOptions>(Configuration); services.AddTransient <ISensorService, SensorService>(); var csv = SensorService.Create(Configuration["sensorDatabase"]); var task = csv.GetAll(); Task.WhenAny(task); var dict = task.Result.ToDictionary(x => x.DeviceId, x => new Device(x) { Status = DeviceStatus.Initializing }); services.AddSingleton(dict); services.AddTransient <ICurrentSensorValues, CurrentSensorValues>(); services.AddMvc(); }
public async Task <ActionResult> Create([FromBody] Sensor sensor) { if (sensor == null || String.IsNullOrEmpty(sensor.MicrocontrollerID)) { return(new UnprocessableEntityResult()); } var Mcu = await microControllerService.FindByID(sensor.MicrocontrollerID); if (Mcu == null) { return(new BadRequestResult()); } var inserted = await sensorService.Create(sensor); if (inserted == null) { return(new BadRequestResult()); } await microControllerService.AddEquipmentReference(inserted.MicrocontrollerID, inserted.Id); return(new OkObjectResult(inserted)); }
public Sensor PostSensor([FromBody] Sensor sensor, int id) { sensor.LabFarm = _labfarmService.GetById(id); return(_sensorService.Create(sensor)); }
public Sensor Post([FromBody] Sensor sensor) { return(_service.Create(sensor)); }