Esempio n. 1
0
        public async Task <ActionResult> EditSensor(string id, [FromBody] Sensor sensor)
        {
            if (sensor == null || String.IsNullOrWhiteSpace(id))
            {
                return(new NotFoundResult());
            }

            var Mcu = await microControllerService.FindByID(sensor.MicrocontrollerID);

            if (Mcu == null)
            {
                return(new BadRequestResult());
            }

            var currentEqp = await sensorService.FindByID(id);



            var valid = await sensorService.Update(id, sensor);

            if (valid)
            {
                if (currentEqp.MicrocontrollerID != sensor.MicrocontrollerID)
                {
                    await microControllerService.UpdateEquipmentReference(oldId : currentEqp.MicrocontrollerID, newId :  sensor.MicrocontrollerID, eqpId : id);
                }


                return(new OkResult());
            }


            return(new BadRequestResult());
        }