Exemplo n.º 1
0
        public async Task <IActionResult> UpdateDeviceType(int id, DeviceTypeUpdateDto deviceTypeUpdateDto)
        {
            var deviceType = await _deviceTypeService.GetDeviceTypeByIdAsync(id);

            if (deviceType == null)
            {
                return(NotFound());
            }

            if (deviceTypeUpdateDto.ParentId == null)
            {
                deviceTypeUpdateDto.ParentId = deviceType.ParentId;
            }

            _mapper.Map(deviceTypeUpdateDto, deviceType);

            if (await _deviceTypeService.UpdateDeviceTypeAsync(deviceType))
            {
                return(NoContent());
            }

            throw new Exception($"Updating device type {id} failed to save");
        }