public override async Task Initialize() { await base.Initialize(); var allClients = await interactorFactory.GetAllClientsInWorkspace(workspaceId).Execute(); Clients = FilterText .Select(text => text ?? string.Empty) .Select(text => { var trimmedText = text.Trim(); var selectableViewModels = allClients .Where(c => c.Name.ContainsIgnoringCase(trimmedText)) .Select(toSelectableViewModel); var isClientFilterEmpty = string.IsNullOrEmpty(trimmedText); var suggestCreation = !isClientFilterEmpty && allClients.None(c => c.Name == trimmedText) && trimmedText.LengthInBytes() <= MaxClientNameLengthInBytes; if (suggestCreation) { var creationSelectableViewModel = new SelectableClientCreationViewModel(trimmedText); selectableViewModels = selectableViewModels.Prepend(creationSelectableViewModel); } else if (isClientFilterEmpty) { selectableViewModels = selectableViewModels.Prepend(noClient); } return selectableViewModels; }); }
private IEnumerable <SelectableClientBaseViewModel> filterClientsByText(string trimmedText, IEnumerable <IThreadSafeClient> allClients) { var selectableViewModels = allClients .Where(c => c.Name.ContainsIgnoringCase(trimmedText)) .OrderBy(client => client.Name) .Select(toSelectableViewModel); var isClientFilterEmpty = string.IsNullOrEmpty(trimmedText); var suggestCreation = !isClientFilterEmpty && allClients.None(c => c.Name == trimmedText) && trimmedText.LengthInBytes() <= MaxClientNameLengthInBytes; if (suggestCreation) { var creationSelectableViewModel = new SelectableClientCreationViewModel(trimmedText); selectableViewModels = selectableViewModels.Prepend(creationSelectableViewModel); } else if (isClientFilterEmpty) { selectableViewModels = selectableViewModels.Prepend(noClient); } return(selectableViewModels); }