Add update device main infos
This commit is contained in:
parent
1ee6f9f382
commit
26253f281e
@ -100,6 +100,7 @@ namespace ManagerService.Controllers
|
|||||||
// Todo add some verification ?
|
// Todo add some verification ?
|
||||||
Device device = new Device();
|
Device device = new Device();
|
||||||
device.Name = newDevice.Name;
|
device.Name = newDevice.Name;
|
||||||
|
device.ConfigurationId = newDevice.ConfigurationId;
|
||||||
device.IpAddress = newDevice.IpAddress;
|
device.IpAddress = newDevice.IpAddress;
|
||||||
device.Connected = newDevice.Connected;
|
device.Connected = newDevice.Connected;
|
||||||
device.ConnectionLevel = newDevice.ConnectionLevel;
|
device.ConnectionLevel = newDevice.ConnectionLevel;
|
||||||
@ -175,6 +176,50 @@ namespace ManagerService.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update device main info
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="updatedDevice">Device to update</param>
|
||||||
|
[ProducesResponseType(typeof(DeviceDTO), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 400)]
|
||||||
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
|
[HttpPut("mainInfos")]
|
||||||
|
public ObjectResult UpdateMainInfos([FromBody] DeviceDTO deviceIn)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (deviceIn == null)
|
||||||
|
throw new ArgumentNullException("Device param is null");
|
||||||
|
|
||||||
|
Device device = _deviceService.GetById(deviceIn.Id);
|
||||||
|
|
||||||
|
if (device == null)
|
||||||
|
throw new KeyNotFoundException("Device does not exist");
|
||||||
|
|
||||||
|
// Todo add some verification ?
|
||||||
|
device.Name = deviceIn.Name;
|
||||||
|
device.Connected = deviceIn.Connected;
|
||||||
|
device.ConfigurationId = deviceIn.ConfigurationId;
|
||||||
|
|
||||||
|
Device deviceModified = _deviceService.Update(device.Id, device);
|
||||||
|
|
||||||
|
return new OkObjectResult(deviceModified.ToDTO());
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
return new BadRequestObjectResult(ex.Message) { };
|
||||||
|
}
|
||||||
|
catch (KeyNotFoundException ex)
|
||||||
|
{
|
||||||
|
return new NotFoundObjectResult(ex.Message) { };
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete a device
|
/// Delete a device
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user