Example #1
0
        public async Task <ActionResult <Device> > PutDeviceAsync(string id, [FromBody] DeviceModel deviceModel)
        {
            ExtractToken();

            if (accessTokenHeader != null)
            {
                var token = appUserTokensRepository.Get(accessTokenHeader);
                if (token != null)
                {
                    var device = await devicesRepository.GetDeviceAsync(id);

                    if (token.AppUserId == device.AppUserId)
                    {
                        device.Name        = deviceModel.Name ?? device.Name;
                        device.Description = device.Description ?? device.Description;
                        await devicesRepository.UpdateDeviceAsync(device);

                        return(device);
                    }
                    return(NotFound());
                }
            }
            return(Unauthorized());
        }