Beispiel #1
0
        public List <AdGridViewModel> GetPageForAdGridByFilter(PageModel pageModel, FilterModel filterModel, out int count, out int maxPrice)
        {
            //business rule : retrieve subcategories for current category and apply to filtering
            List <Guid> categoryIds = new List <Guid>();

            if (filterModel.CategoryId != null && filterModel.CategoryId != Guid.Empty)
            {
                categoryIds = _categoryRepository.GetSubcategoriesIdForCategory((Guid)filterModel.CategoryId, pageModel.CountryId);
            }

            FilterRepositoryModel repositoryModel = FilterModelMapper.MapToFilterRepositoryModel(filterModel, categoryIds, pageModel.CountryId);
            List <Ad>             sourceEntities;

            switch (pageModel.ColumnName.ToLower())
            {
            case "name":
                sourceEntities = _repository.GetAdGridByFilters(pageModel.SearchString, repositoryModel);
                break;

            default:
                sourceEntities = _repository.GetAdGridByFilters(repositoryModel);
                break;
            }

            if (sourceEntities == null)
            {
                throw new Exception(LOCALIZATION_AD_NOT_FOUND);
            }
            sourceEntities = _repository.OrderAdsByColumn(sourceEntities, pageModel.SortColumn);
            maxPrice       = (int)_repository.GetMaximumPriceForAd();
            count          = sourceEntities.Count;

            var entities = _repository.GetAdPage(sourceEntities, pageModel.PageIndex, pageModel.PageSize);

            if (entities == null)
            {
                throw new Exception(LOCALIZATION_AD_NOT_FOUND);
            }

            var list = AdMapper.MapToAdGridModel(entities);

            foreach (var ad in list)
            {
                ad.IsInWishlist = _wishlistRepository.Exists(ad.ID, pageModel.CurrentUser);
            }
            return(list);
        }
Beispiel #2
0
        public List <AdGridViewModel> GetPageForAdGrid(PageModel pageModel, out int count, out int maxPrice)
        {
            List <Ad> sourceEntities;

            switch (pageModel.ColumnName.ToLower())
            {
            case "name":
                sourceEntities = _repository.GetAdGrid(pageModel.SearchString, pageModel.CountryId);
                break;

            default:
                sourceEntities = _repository.GetAdGrid(pageModel.CountryId);
                break;
            }

            if (sourceEntities == null)
            {
                throw new Exception(LOCALIZATION_AD_NOT_FOUND);
            }
            sourceEntities = _repository.OrderAdsByColumn(sourceEntities, pageModel.SortColumn);
            maxPrice       = (int)_repository.GetMaximumPriceForAd();
            count          = sourceEntities.Count;

            var entities = _repository.GetAdPage(sourceEntities, pageModel.PageIndex, pageModel.PageSize);

            if (entities == null)
            {
                throw new Exception(LOCALIZATION_AD_NOT_FOUND);
            }

            var list = AdMapper.MapToAdGridModel(entities);

            foreach (var ad in list)
            {
                ad.IsInWishlist = _wishlistRepository.Exists(ad.ID, pageModel.CurrentUser);
            }

            return(list);
        }
Beispiel #3
0
        private List <AdGridViewModel> LoadRelatedAdsForCategories(Guid currentCategoryId)
        {
            var relatedAds = RecursivelyLoadRelatedAdsForCategory(currentCategoryId);

            return(AdMapper.MapToAdGridModel(relatedAds));
        }