コード例 #1
0
        public async Task ActivateSmartDeviceAsync(ActivateSmartDeviceRequest activateSmartDeviceRequest, Guid partnerId)
        {
            LoginRequest loginRequest = new LoginRequest()
            {
                Login    = activateSmartDeviceRequest.SerialNumber,
                Password = activateSmartDeviceRequest.DefaultPassword
            };
            SmartDevice smartDevice = await GetSmartDeviceByLoginPassword(loginRequest);

            if (smartDevice.Mode != SmartDeviceMode.Inactive)
            {
                throw new Exception(_localizer["The smart device cannot be activated."]);
            }

            bool smartDeviceReceivedMessage = await _smartDeviceHubService.TrySendActivateMessageAsync(
                smartDevice.Id, activateSmartDeviceRequest.NewPassword);

            if (!smartDeviceReceivedMessage)
            {
                throw new Exception(_localizer["The smart device is not connected to the service."]);
            }

            smartDevice.Activate(partnerId, _passwordService.GeneratePassword(activateSmartDeviceRequest.NewPassword));
            await _dbContext.SaveChangesAsync();
        }
コード例 #2
0
        public async Task <IActionResult> Activate([FromBody] ActivateSmartDeviceRequest activateSmartDeviceRequest)
        {
            Guid partnerId = Guid.Parse(User.Identity.Name);

            try
            {
                await _smartDeviceService.ActivateSmartDeviceAsync(activateSmartDeviceRequest, partnerId);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(new BadRequestResponseMessage(e.Message)));
            }
        }