Exemplo n.º 1
0
        public void SelectEntities()
        {
            if (SearchCriteria != null)
            {
                try
                {
                    long directoryId = SelectedItem?.Id ?? -1L;

                    Entities.Clear();
                    List <DirectoryItem> loadedEntities = GetItems();

                    if (SearchCriteria != null)
                    {
                        SearchCriteria.DirectoryItems = GetDirectiryItems(loadedEntities);

                        if (SearchCriteria.SelectedDirectoryItems != null && SearchCriteria.SelectedDirectoryItems.Any())
                        {
                            SearchCriteria.DirectoryItems.ForEach(x => x.Selected = SearchCriteria.SelectedDirectoryItems.Any(d => d.Id == x.Id && d.Selected));
                            SearchCriteria.SelectedDirectoryItems.Clear();
                            SearchCriteria.DirectoryItems.Where(x => x.Selected).ToList().ForEach(s => SearchCriteria.SelectedDirectoryItems.Add(s));
                        }
                    }

                    DirectoryItem directoryItem = loadedEntities?.FirstOrDefault(x => x != null && x.Id == directoryId) ?? Entities?.FirstOrDefault();

                    Application.Current.Dispatcher.Invoke(
                        () =>
                    {
                        Entities.AddRange(loadedEntities);
                        OnPropertyChanged(nameof(Entities));
                        SelectedItem = directoryItem;
                        SearchCriteria?.DirectoryComplited();
                    });
                }
                catch (Exception e)
                {
                    ;
                    //throw;
                }
            }
        }