コード例 #1
0
        /// <summary>
        /// Toggles a device from inactive to active.
        /// </summary>
        /// <param name="account"></param>
        /// <param name="device"></param>
        /// <returns></returns>
        public IDeviceActivationResult ActivateDevice(IAccount account, IDevice device)
        {
            IDeviceActivationResult result = null;

            var deviceValidationResult = ValidateDevice(device);

            if (deviceValidationResult is DeviceFailureResult)
            {
                result = new DeviceActivationFailureResult()
                {
                    Item = device, Data = deviceValidationResult.Data
                };
            }
            else
            {
                if (ValidateAccount(account))
                {
                    var deviceResult = _deviceRepository.GetItem(device.DeviceId);

                    if (deviceResult is DeviceSuccessResult)
                    {
                        deviceResult.Item.IsActive = true;
                        var updateResult = _deviceRepository.UpdateItem(deviceResult.Item);

                        if (updateResult is DeviceSuccessResult)
                        {
                            result = new DeviceActivationSuccessResult();
                        }
                        else
                        {
                            result = new DeviceActivationFailureResult()
                            {
                                Data = updateResult.Data
                            };
                        }
                    }
                    else
                    {
                        result = new DeviceActivationFailureResult();
                        result.AddData(new List <string>()
                        {
                            "Unable to retrieve device."
                        });
                    }
                }
                else
                {
                    result = new DeviceActivationFailureResult()
                    {
                        Item = device
                    };
                    result.AddData(new List <string>()
                    {
                        "The account is not valid."
                    });
                }
            }

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Toggles a device from active to inactive
        /// </summary>
        /// <param name="account"></param>
        /// <param name="device"></param>
        /// <returns></returns>
        public IDeviceActivationResult DeactivateDevice(IAccount account, IDevice device)
        {
            IDeviceActivationResult result = null;

            //Verify that the account is valid.
            if (ValidateAccount(account))
            {
                device.IsActive = false;
                var deactivationResult = _deviceRepository.UpdateItem(device);

                if (deactivationResult is DeviceSuccessResult)
                {
                    result = new DeviceActivationSuccessResult();
                }
                else
                {
                    result = new DeviceActivationFailureResult()
                    {
                        Item = device, Data = deactivationResult.Data
                    };
                }
            }
            else
            {
                result = new DeviceActivationFailureResult()
                {
                    Item = device
                };
                result.AddData(new List <string>()
                {
                    "The account is not valid."
                });
            }

            return(result);
        }