Beispiel #1
0
        public async Task <ActionResult> CellularActionRequest(CellularActionRequestModel model)
        {
            if (model == null)
            {
                throw new ArgumentException(nameof(model));
            }
            if (string.IsNullOrWhiteSpace(model.DeviceId))
            {
                throw new ArgumentException(nameof(model.DeviceId));
            }

            var device = await _deviceLogic.GetDeviceAsync(model.DeviceId);

            if (device == null)
            {
                throw new InvalidOperationException("Unable to find device with deviceId " + model.DeviceId);
            }
            var iccid = device.SystemProperties.ICCID;

            if (string.IsNullOrWhiteSpace(iccid))
            {
                throw new InvalidOperationException("Device does not have an ICCID. Cannot complete cellular actions.");
            }

            CellularActionUpdateResponseModel result = await processActionRequests(device, model.CellularActions);

            var viewModel = generateSimInformationViewModel(iccid, result);

            return(PartialView("_CellularInformation", viewModel));
        }
Beispiel #2
0
        private SimInformationViewModel generateSimInformationViewModel(string iccid, CellularActionUpdateResponseModel actionResponstModel = null)
        {
            var viewModel = new SimInformationViewModel();

            viewModel.TerminalDevice = _cellularExtensions.GetSingleTerminalDetails(new Iccid(iccid));
            viewModel.SessionInfo    = _cellularExtensions.GetSingleSessionInfo(new Iccid(iccid)).LastOrDefault() ?? new SessionInfo();

            var apiProviderDetails = _apiRegistrationRepository.RecieveDetails();

            viewModel.ApiRegistrationProvider = Convert.ToString(apiProviderDetails.ApiRegistrationProvider, CultureInfo.CurrentCulture);
            viewModel.AvailableSimStates      = _cellularExtensions.GetValidTargetSimStates(iccid, viewModel.TerminalDevice.Status);

            try
            {
                viewModel.AvailableSubscriptionPackages = _cellularExtensions.GetAvailableSubscriptionPackages(iccid, viewModel.TerminalDevice.RatePlan);
            }
            catch
            {
                // [WORKAROUND] GetAvailableSubscriptionPackages does not work
                viewModel.AvailableSubscriptionPackages = new List <DeviceManagement.Infrustructure.Connectivity.Models.Other.SubscriptionPackage>();
            }

            viewModel.CellularActionUpdateResponse = actionResponstModel;

            try
            {
                IEnumerable <string> availableLocaleNames;
                string currentLocaleName = _cellularExtensions.GetLocale(iccid, out availableLocaleNames);

                viewModel.CurrentLocaleName    = currentLocaleName;
                viewModel.AvailableLocaleNames = availableLocaleNames;
            }
            catch
            {
                viewModel.CurrentLocaleName    = string.Empty;
                viewModel.AvailableLocaleNames = new List <string>();
            }

            var state = _cellularExtensions.GetLastSetLocaleServiceRequestState(iccid);

            if (string.Equals(state, "IN_PROGRESS") || string.Equals(state, "PENDING"))
            {
                viewModel.LastServiceRequestState = state;
            }

            return(viewModel);
        }