public async Task <AdIndexViewModel> PrepearingAdIndexViewModel(List <AdDTO> ads, int selectedProductTypeId)
        {
            AdIndexViewModel adIndexViewModel = new AdIndexViewModel {
                SimpleAds = ads
            };
            var dataForFilter = _adService.GetDataForCreatingAdOrDataForFilter();

            adIndexViewModel.SearchFilter  = new SearchFilterViewModel();
            adIndexViewModel.SortViewModel = new SortViewModel();
            adIndexViewModel.Filter        = new FilterViewModel();

            adIndexViewModel.Filter.ProductsModelFilters = new List <ProductsModelFilter>();
            adIndexViewModel.Filter.ProductMemmories     = new List <ProductMemmoriesFilter>();
            adIndexViewModel.Filter.ProductsColors       = new List <ProductsColorFilter>();

            adIndexViewModel.Filter.ProductsModelFilters =
                GetProductModelsDataForFilter(dataForFilter.productModelsDTO, selectedProductTypeId);

            adIndexViewModel.Filter.ProductMemmories =
                GetProductMemmoriesDataForFilter(dataForFilter.productMemoriesDTO);

            adIndexViewModel.Filter.ProductsColors =
                GetProductColorsDataFilter(dataForFilter.productColorsDTO);

            adIndexViewModel.SortViewModel.SortOptionList        = GetSerachSelectionOptionsList();
            adIndexViewModel.SearchFilter.ProductTypesOptionList = GetProductTypeSelectionOptionsList();
            adIndexViewModel.SearchFilter.SelectedProductTypeId  = selectedProductTypeId;

            adIndexViewModel.Filter.SelectedProductTypeId = adIndexViewModel.SearchFilter.SelectedProductTypeId;

            return(adIndexViewModel);
        }
Ejemplo n.º 2
0
        public async Task <List <AdDTO> > FilteringData(
            string titleFilter,
            string productState,
            List <AdDTO> adQueryResult,
            AdIndexViewModel model)
        {
            if (!string.IsNullOrEmpty(titleFilter))
            {
                adQueryResult = adQueryResult.Where(x => x.Title.ToLower().Contains(titleFilter.ToLower())).ToList();
            }

            if (model.SearchFilter == null)
            {
                model.SearchFilter = new SearchFilterViewModel()
                {
                    SelectedProductTypeId = adQueryResult.FirstOrDefault().Characteristics.ProductType.ProductTypesId
                }
            }
            ;

            adQueryResult = new SerarchNavFilter(model, adQueryResult).SearchNavChanged();

            if (model.SortViewModel != null)
            {
                adQueryResult = new SelectedOptionFilter(model.SortViewModel.SelectedOptionValue, adQueryResult).SelectedOptionChanged();
            }

            adQueryResult = await new CheckBoxFilter(model, adQueryResult).GetFilteredAdsData();
            adQueryResult = new ButtonAreaFilter(productState, adQueryResult).GetFilteredAdsData();

            return(adQueryResult);
        }
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    _model  = null;
                    _adList = null;
                }

                disposed = true;
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Index(int page = 1)
        {
            int pageSize           = 5;
            AdIndexViewModel model = new AdIndexViewModel {
                SimpleAds = new List <AdDTO>()
            };

            var result = await _adService.GetActiveAds();

            if (!result.Succedeed)
            {
                return(View(model));
            }

            int count = model.SimpleAds.Count();

            model.PageViewModel = new PageViewModel(count, page, pageSize);
            model.SimpleAds     = model.SimpleAds.Skip((page - 1) * pageSize).Take(pageSize).ToList();

            return(View(model));
        }
Ejemplo n.º 5
0
        // GET: Ads
        public ActionResult Index(string SearchString, String city, double from = 0.0, double to = 0.0, int page = 1)
        {
            var ads = db.Ads.OfType <Ad>().Where(w => w.Discriminator == DiscriminatorOptions.Ad && w.User.Confirmed);

            ViewBag.Views     = db.Views;
            ViewBag.Wishlists = db.Wishlists;
            if (!String.IsNullOrEmpty(SearchString))
            {
                ads = ads.Where(a => a.City.Name.ToUpper().Contains(SearchString.ToUpper()) ||
                                a.AdDescribtion.ToUpper().Contains(SearchString.ToUpper()) ||
                                a.AdTitle.ToUpper().Contains(SearchString.ToUpper()));
            }
            if (!String.IsNullOrEmpty(city))
            {
                ads = ads.Where(a => a.City.Name.ToUpper().Equals(city));
            }

            if (to >= from && to > 1 && from >= 0.0)
            {
                ads = ads.Where(a => a.AdPrice >= from && a.AdPrice <= to);
            }
            var cities = ads.Select(c => c.City.Name).Distinct();

            ViewBag.city = new SelectList(cities);
            //pagination steps
            int pageSize            = 6;
            var pager               = new Pager(ads.Count(), page, pageSize);
            AdIndexViewModel vModel = new AdIndexViewModel()
            {
                Ads          = ads.OrderBy(a => a.AdPrice).Skip((pager.CurrentPage - 1) * pager.PageSize).Take(pager.PageSize),
                Pager        = pager,
                SearchString = SearchString,
                City         = city,
                From         = from,
                To           = to
            };

            return(View(vModel));
        }
Ejemplo n.º 6
0
        public async Task <AdIndexViewModel> PrepearingFilter(List <AdDTO> adQueryResult, AdIndexViewModel model)
        {
            if (model.Filter == null)
            {
                model = await _prepearingModel.PrepearingAdIndexViewModel(adQueryResult, model.SearchFilter.SelectedProductTypeId);
            }
            else
            {
                model.SortViewModel.SortOptionList =
                    _prepearingModel.GetSerachSelectionOptionsList();

                model.SearchFilter.ProductTypesOptionList =
                    _prepearingModel.GetProductTypeSelectionOptionsList();

                model.Filter.SelectedProductTypeId =
                    model.SearchFilter.SelectedProductTypeId;

                model.SimpleAds = adQueryResult.ToList();
            }

            return(model);
        }
 public CheckBoxFilter(AdIndexViewModel model, List <AdDTO> adList)
 {
     _model  = model;
     _adList = adList;
 }
        public async Task <IActionResult> Index(string titleFilter, string cityFilter, string productState, AdIndexViewModel model, int page = 1)
        {
            int pageSize = 5;

            var result = await _adService.GetActiveAds();

            if (!result.Succedeed)
            {
                return(View(model));
            }

            var topAds = await _adService.GetActiveRandomTopAds();

            List <AdDTO> adQueryResult = result.Property;

            adQueryResult = await _adFilter.FilteringData(titleFilter, productState, adQueryResult, model);

            model = await _adFilter.PrepearingFilter(adQueryResult, model);

            if (topAds.Property.Count() > 0)
            {
                model.TopAds = topAds.Property.ToList();
            }

            int           count         = model.SimpleAds.Count();
            PageViewModel pageViewModel = new PageViewModel(count, page, pageSize);

            model.PageViewModel = pageViewModel;
            model.SimpleAds     = model.SimpleAds.Skip((page - 1) * pageSize).Take(pageSize).ToList();

            return(View(model));
        }
Ejemplo n.º 9
0
 public SerarchNavFilter(AdIndexViewModel model, List <AdDTO> ads)
 {
     _model = model;
     _query = ads;
 }