Ejemplo n.º 1
0
        public async Task <IActionResult> Search(HomeIndexViewModel model)
        {
            var viewModel = new SearchViewModel
            {
                SearchText = model.SearchText,
                Area       = model.Area,
                Country    = model.Country,
                Category   = model.Category,
                MinPrice   = model.MinPrice,
                MaxPrice   = model.MaxPrice,
            };

            viewModel.Stocks = new PagedList <ProductListingServiceModel>(await this.products.SearchAsync(model.SearchText), 1, 12);
            viewModel.Users  = await this.users.SearchAsync(model.SearchText);

            viewModel.Filter();

            string searchTxt = string.IsNullOrWhiteSpace(model.SearchText) ? (model.Category == null ? "anything" : model.Category.ToString()) : model.SearchText;

            if (User.Identity.IsAuthenticated)
            {
                await this.userActivities.AddUserActivity(string.Format(SearchedFor, searchTxt), User.Identity.Name);
            }

            return(View(viewModel));
        }