Beispiel #1
0
        public async Task <ObservableCollection <ICategoriesItemVM> > LoadItemsFor(string categoryId = null)
        {
            ObservableCollection <ICategoriesItemVM> dataSource = null;

            try
            {
                IEnumerable <Category> categories;

                if (!CachedObjects.ContainsKey(categoryId.IsNullOrEmtpy() ? "null" : categoryId))
                {
                    categories = await CategoriesService.LoadCategories(categoryId);

                    if (!categories.IsNullOrEmpty())
                    {
                        CachedObjects.Add(categoryId.IsNullOrEmtpy() ? "null" : categoryId, categories);
                    }
                }
                else
                {
                    categories = CachedObjects[categoryId.IsNullOrEmtpy() ? "null" : categoryId].Cast <Category>();
                }

                dataSource = new ObservableCollection <ICategoriesItemVM>(categories.Select(c => SetupItem(c)));
            }
            catch (ConnectionException ex)
            {
                OnConnectionException(ex);
            }
            catch (Exception ex)
            {
                OnException(ex);
            }

            return(dataSource);
        }
Beispiel #2
0
        protected TResult GetObject <TResult>(Func <TResult> createObject) where TResult : class
        {
            var key = typeof(TResult);

            if (!CachedObjects.ContainsKey(key))
            {
                CachedObjects.Add(key, createObject());
            }
            return(CachedObjects[key] as TResult);
        }
        public async Task <ObservableCollection <IFiltersItemVM> > LoadFiltersFor(string categoryId, List <ApplyedFilter> applyedFilters)
        {
            ObservableCollection <IFiltersItemVM> dataSource = null;

            try
            {
                IEnumerable <Filter> filters = null;

                if (categoryId.IsNullOrEmtpy())
                {
                    filters = await FiltersService.LoadFilters(categoryId);
                }
                else if (!CachedObjects.ContainsKey(categoryId))
                {
                    filters = await FiltersService.LoadFilters(categoryId);

                    if (!filters.IsNullOrEmpty())
                    {
                        CachedObjects.Add(categoryId, filters);
                    }
                }
                else if (CachedObjects.ContainsKey(categoryId))
                {
                    filters = CachedObjects[categoryId].Cast <Filter>();
                }

                dataSource = new ObservableCollection <IFiltersItemVM>(filters
                                                                       .Select(filter => CreateItemForFilter(filter, applyedFilters))
                                                                       .Where(x => x != null)
                                                                       );
            }
            catch (ConnectionException ex)
            {
                OnConnectionException(ex);
            }
            catch (Exception ex)
            {
                OnException(ex);
            }

            return(dataSource);
        }
Beispiel #4
0
        public async Task <ObservableCollection <ISortItemVM> > LoadSortTypesInCategory(string categoryId, string selectedSortId)
        {
            ObservableCollection <ISortItemVM> dataSource = null;

            try
            {
                IEnumerable <SortType> sortTypes = null;

                if (categoryId.IsNullOrEmtpy())
                {
                    sortTypes = await FiltersService.LoadSortTypes(categoryId);
                }
                else if (!CachedObjects.ContainsKey(categoryId))
                {
                    sortTypes = await FiltersService.LoadSortTypes(categoryId);

                    if (!sortTypes.IsNullOrEmpty())
                    {
                        CachedObjects.Add(categoryId, sortTypes);
                    }
                }
                else if (CachedObjects.ContainsKey(categoryId))
                {
                    sortTypes = CachedObjects[categoryId].Cast <SortType>();
                }

                dataSource = new ObservableCollection <ISortItemVM>(sortTypes.Select(c => SetupItem(c, selectedSortId)));
            }
            catch (ConnectionException ex)
            {
                OnConnectionException(ex);
            }
            catch (Exception ex)
            {
                OnException(ex);
            }

            return(dataSource);
        }