public async Task <IActionResult> Log(logWithStatus log)
        {
            var device = await repo.GetDevice(log.DeviceID);

            if (device == null)
            {
                return(NotFound($"Device with deviceID={log.DeviceID} not available"));
            }
            if (device.isEnabled == false)
            {
                return(BadRequest($"Device is disabled please contact administer"));
            }
            var ispram = "";

            foreach (var item in device.deviceParams)
            {
                if (item.ParamID == log.PramID)
                {
                    ispram       = log.PramID;
                    log.minValue = item.Min;
                    log.maxValue = item.Max;
                    break;
                }
            }
            if (ispram == "")
            {
                return(NotFound($"Device does not have param={log.PramID} not available"));
            }
            var created_log = await repo.CreateLog(log);

            return(Ok("Success"));
        }
Esempio n. 2
0
        public async Task <Device_log> CreateLog(logWithStatus log)
        {
            var device = await _context.m_device.FirstOrDefaultAsync(e => e.DeviceID == log.DeviceID);;

            device.Battery = log.Battery;
            device.Healthy = log.Healthy;
            var Device_log = new Device_log();

            Device_log.DeviceID  = log.DeviceID;
            Device_log.RefID     = log.RefID;
            Device_log.dateTime  = DateTime.Now;
            Device_log.PramID    = log.PramID;
            Device_log.value     = log.value;
            Device_log.minValue  = log.minValue;
            Device_log.maxValue  = log.maxValue;
            Device_log.avgValue  = log.avgValue;
            Device_log.Threshold = log.Threshold;
            var new_log = await _context.Device_log.AddAsync(Device_log);

            await _context.SaveChangesAsync();

            return(new_log.Entity);
        }