Пример #1
0
        private IObservable <IThreadSafeClient> pickClient()
        {
            return(currentWorkspace.FirstAsync()
                   .SelectMany(currentWorkspace => currentClient.FirstAsync()
                               .SelectMany(currentClient => clientFromViewModel(currentClient, currentWorkspace))));

            IObservable <IThreadSafeClient> clientFromViewModel(IThreadSafeClient currentClient, IThreadSafeWorkspace currentWorkspace)
            => Navigate <SelectClientViewModel, SelectClientParameters, long?>(
                SelectClientParameters.WithIds(currentWorkspace.Id, currentClient?.Id))
            .ToObservable()
            .SelectMany(clientFromId);

            IObservable <IThreadSafeClient> clientFromId(long?selectedClientId)
            {
                if (selectedClientId == null)
                {
                    return(Observable.Empty <IThreadSafeClient>());
                }

                if (selectedClientId.Value == 0)
                {
                    return(Observable.Return <IThreadSafeClient>(null));
                }

                return(interactorFactory.GetClientById(selectedClientId.Value).Execute());
            }
        }
        private async Task pickClient()
        {
            var parameter        = SelectClientParameters.WithIds(workspaceId, clientId);
            var selectedClientId =
                await navigationService.Navigate <SelectClientViewModel, SelectClientParameters, long?>(parameter);

            if (selectedClientId == null)
            {
                return;
            }

            if (selectedClientId.Value == 0)
            {
                clientId   = null;
                ClientName = "";
                updateIsNameAlreadyTaken();
                return;
            }

            var client = await interactorFactory.GetClientById(selectedClientId.Value).Execute();

            clientId   = client.Id;
            ClientName = client.Name;
            updateIsNameAlreadyTaken();
        }