EasyBike.Models.Contract.GetStationsAsync C# (CSharp) Method

GetStationsAsync() public method

public GetStationsAsync ( ) : Task>
return Task>
        public async Task<List<Station>> GetStationsAsync()
        {
            var serviceProviderModels = await InnerGetStationsAsync().ConfigureAwait(false);
            var stations = new List<Station>(serviceProviderModels.Count);
            foreach (var serviceProviderModel in serviceProviderModels)
            {
                stations.Add(new Station()
                {
                    AvailableBikes = serviceProviderModel.AvailableBikes,
                    AvailableBikeStands = serviceProviderModel.AvailableBikeStands,
                    ContractStorageName = StorageName,
                    Id = serviceProviderModel.Id,
                    IsUiRefreshNeeded = StationRefreshGranularity ? false : true,
                    Latitude = serviceProviderModel.Latitude,
                    Longitude = serviceProviderModel.Longitude,
                    Loaded = ImageAvailability ? false : true,
                    Status = serviceProviderModel.Status,
            });
            }
            return stations;
        }

Usage Example

        public async Task<bool> AddOrRemoveContract(Contract contract)
        {
            if (contract.Downloading)
            {
                return true;
            }
            try
            {
                if (contract.Downloaded)
                {
                    await _contractsService.RemoveContractAsync(contract);
                    contract.Downloaded = false;
                }
                else
                {
                    if (CrossConnectivity.Current.IsConnected)
                    {
                        contract.Downloading = true;
                    var stations = await contract.GetStationsAsync();
                    contract.Stations = stations;
                    contract.StationCounter = stations.Count();
                    contract.Downloaded = true;
                    contract.Downloading = false;
                    await _contractsService.AddContractAsync(contract);
                    }
                    else
                    {
                        try
                        {
                            await _dialogService.ShowMessage("Apparently you network connection is off. I'm afraid you'll not be able to download a city if you don't have any active network connection.", "Oops !");
                        }
                        catch { }
                    }

                }
            }
            catch (Exception e)
            {
                var message = $"You seems to struggle downloading {contract.Name}. It may be either that your network connection isn't healthy, the service provider is down or it has changed. If you think it could be the last option, then contact us and we will investigate. Thumbs up!";
                try
                {
                    // this can throw a application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))
                    // better to catch this as I have found a way to force it to the UI thread from the cross platform library
                    await _dialogService.ShowMessage(message,
                      "Oops !",
                      buttonConfirmText: "Ok", buttonCancelText: "Contact us",
                      afterHideCallback: (confirmed) =>
                      {
                          if (!confirmed)
                          {
                              _notificationService.Notify(new SendEmailNotification()
                              {
                                  Subject = $"Download city: unable to download {contract.Name}",
                                  Body = $"Hey folks ! I'm unable to download {contract.Name} with the following error: " +
                                   $"Message: { e.Message } Inner: {e.InnerException} Stack: {e.StackTrace}",
                              });
                          }
                      });
                }
                catch { }
            }
            finally
            {
                contract.Downloading = false;
            }
            return true;
        }