예제 #1
0
        public async Task <IActionResult> Create(Guid deviceId, [Bind("Id, DateTime,SoilMoisture,SoilDescription,AirHumidity,AirTemperature,LightState,DeviceName")] Entry entry)
        {
            if (!ModelState.IsValid)
            {
                return(View(entry));
            }
            await _repository.AddAsync(entry, await GetDeviceAsync(deviceId));

            return(RedirectToAction(nameof(Index), new { deviceId }));
        }
예제 #2
0
        public async Task <IActionResult> PostMeasure([FromBody] MeasureDevice measureDevice)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Device dev = await _deviceRepository.GetAsync(measureDevice.deviceId);

            if (dev == null)
            {
                return(NotFound(measureDevice.deviceId));
            }
            await _hubContext.Clients.Group(GetUserName()).InvokeAsync("newEntry", dev.Name);

            if (await _repository.AddAsync(measureDevice.Entry, dev))
            {
                return(Ok(
                           await _repository.GetAsync(measureDevice.Entry.DateTime, dev)));
            }
            return(BadRequest());
        }
예제 #3
0
        public async Task RecordAsync(string name, float value, string unit, DateTime date)
        {
            var measure = new Measure(name, value, unit, date);

            await _measureRepository.AddAsync(measure);
        }