public async Task <IActionResult> Add([FromBody] ArduinoDeviceDto dto)
        {
            if (dto == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = await _userManager.GetUserAsync(User);

            var device = dto.MapToArduinoDevice(user.Id);

            using (var uow = _unitOfWork.Create())
            {
                try
                {
                    await _deviceService.AddAsync(device);

                    uow.Commit();
                }
                catch (DeviceAlreadyExistsException)
                {
                    return(StatusCode(409));
                }
            }

            return(Ok(device));
        }
        public async Task <IActionResult> Update(int id, [FromBody] ArduinoDeviceDto dto)
        {
            if (dto == null || id == 0)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var authorizationResult = await _authorizationService.Authorize(User, id);

            if (!authorizationResult)
            {
                return(Forbid());
            }

            var device = dto.MapToArduinoDevice();

            using (var uow = _unitOfWork.Create())
            {
                try
                {
                    await _deviceService.UpdateAsync(id, device);

                    uow.Commit();
                }
                catch (RecordNotFoundException)
                {
                    return(NotFound());
                }
            }

            return(Ok(device));
        }