public async Task OnGetAsync()
        {
            var device = await _deviceAppService.GetAsync(Id);

            try
            {
                Device = ObjectMapper.Map <DeviceDto, DeviceUpdateDto>(device);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#2
0
        public async Task <IActionResult> UpdateDevice(string deviceId, [FromBody] DeviceUpdateDto deviceRegistrationDto)
        {
            //TODO : Create DTO for update (with only allowed fields)
            Device device = Mapper.Map <Device>(deviceRegistrationDto);

            device.Id = deviceId;

            var isUpdated = deviceService.Update(deviceId, device);

            if (isUpdated)
            {
                return(Ok());
            }

            return(NoContent());
        }
        public async Task <IActionResult> UpdateDevice(int id, DeviceUpdateDto deviceUpdateDto)
        {
            var device = await _deviceService.GetDeviceByIdAsync(id);

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

            _mapper.Map(deviceUpdateDto, device);

            if (await _deviceService.UpdateDeviceAsync(device))
            {
                return(NoContent());
            }

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