Ejemplo n.º 1
0
        public async Task <IEnumerable <ItemViewModel> > Search([FromQuery] ItemSearchViewModel itemSearch)
        {
            var serchExpression = GenerateExpressionForSearch(itemSearch);
            var items           = _mapper.Map <IEnumerable <ItemViewModel> >(await _itemRepository.Find(serchExpression));

            return(items);
        }
Ejemplo n.º 2
0
        public async Task OnGetAsync(string pageNo, string status, string id, string street, string itemCategory, string ownerName, string customerId,
                                     string features, string facilities, string propertyCategory, string district, bool deleted, string ownerMobile, string dateFrom, string dateTo, string creatorId, string hasFeature, bool?removeDuplicates, bool?negotiable, bool?hasPicture)
        {
            SearchInput = new ItemSearchViewModel
            {
                PageNo              = pageNo.FixPageNumber(),
                Address             = street,
                ItemCategory        = itemCategory,
                Owner               = ownerName,
                ItemId              = id,
                CustomerId          = customerId,
                FeaturesJson        = features,
                FacilitiesJson      = facilities,
                PropertyCategory    = propertyCategory,
                District            = district,
                IncludeDeletedItems = deleted,
                OwnerMobile         = ownerMobile,
                CreationDateFrom    = dateFrom,
                CreationDateTo      = dateTo,
                CreatorId           = creatorId,
                HasFeature          = hasFeature,
                IsNegotiable        = negotiable != null && negotiable == true,
                HasPicture          = hasPicture != null && hasPicture == true
            };

            Status = !string.IsNullOrEmpty(status)
                ? status
                : null;
            List = await _itemService.ItemListAsync(SearchInput, false);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Search(string query, int pageIndex = 1)
        {
            query = query?.Trim();

            if (query == null || query.Length < 3)
            {
                this.ShowErrorMessage(NotificationMessages.SearchQueryTooShort);

                return(this.RedirectToHome());
            }

            var serviceItems = (await this.itemsService
                                .SearchByTitleAsync <ItemListingServiceModel>(query))
                               .ToArray();

            if (!serviceItems.Any())
            {
                this.ShowErrorMessage(NotificationMessages.SearchNoItems);

                return(this.RedirectToHome());
            }

            var allItems = serviceItems.Select(Mapper.Map <ItemListingDto>)
                           .ToPaginatedList(pageIndex, WebConstants.ItemsCountPerPage);

            var items = new ItemSearchViewModel
            {
                Items = allItems,
                Query = query
            };

            this.ViewData[WebConstants.SearchViewDataKey] = query;

            return(this.View(items));
        }
Ejemplo n.º 4
0
        private Expression <Func <Item, bool> > GenerateExpressionForSearch(ItemSearchViewModel itemSearch)
        {
            var searchHelper = new SearchHelper <Item>();

            if (itemSearch.MinPrice != null)
            {
                searchHelper
                .AddAndExpression("Price", itemSearch.MinPrice, ExpressionOperation.GreaterThanOrEqualTo);
            }

            if (itemSearch.MaxPrice != null)
            {
                searchHelper
                .AddAndExpression("Price", itemSearch.MaxPrice, ExpressionOperation.LessThanOrEqualTo);
            }

            if (itemSearch.MinQuantity != null)
            {
                searchHelper
                .AddAndExpression("Quantity", itemSearch.MinQuantity, ExpressionOperation.GreaterThanOrEqualTo);
            }
            if (itemSearch.MaxQuantity != null)
            {
                searchHelper
                .AddAndExpression("Quantity", itemSearch.MaxQuantity, ExpressionOperation.LessThanOrEqualTo);
            }

            if (!string.IsNullOrWhiteSpace(itemSearch.Name))
            {
                searchHelper
                .AddAndExpression("Name", itemSearch.Name, ExpressionOperation.Contains);
            }

            if (!string.IsNullOrWhiteSpace(itemSearch.Description))
            {
                searchHelper
                .AddAndExpression("Description", itemSearch.Description, ExpressionOperation.Contains);
            }

            if (itemSearch.Enabled != null && !(bool)itemSearch.Enabled)
            {
                searchHelper
                .AddAndExpression("DisabledAt", null, ExpressionOperation.NotEqualTo);
            }

            if (itemSearch.Enabled != null && (bool)itemSearch.Enabled)
            {
                searchHelper
                .AddAndExpression("DisabledAt", null);
            }

            return(searchHelper.BuildExpression());
        }
Ejemplo n.º 5
0
        public IActionResult Index(ItemSearchViewModel searchModel)
        {
            ItemModel result = new ItemModel();

            using (StreamReader r = new StreamReader("warehouse.json"))
            {
                string json = r.ReadToEnd();
                result = JsonConvert.DeserializeObject <ItemModel>(json);
            }

            // TODO search
            //result.Item = result.Item.Where(m => m.Name.Contains(searchModel.Name) && m.Material.Contains(searchModel.Material)).ToList();

            return(PartialView(result));

            //return View(result);
        }
        public ActionResult Search(SearchItemRequestModel input)
        {
            int    page = 1;
            string word = "";

            if (input.Search != null)
            {
                word = input.Search;
            }

            var items = itemRepository.All().Where(i => i.Title.Contains(word) || i.Description.Contains(word));

            if (input.Category != null)
            {
                var categoriesString = String.Join("", input.Category);
                items = items.Where(i => categoriesString.Contains(i.Category.Name));
            }

            decimal totalPages = Math.Ceiling((decimal)items.Count() / input.PageSize);

            switch (input.Sort)
            {
            case "Description": items = items.OrderBy(e => e.Description).Skip((page - 1) * input.PageSize).Take(input.PageSize); break;

            case "Title": items = items.OrderBy(e => e.Title).Skip((page - 1) * input.PageSize).Take(input.PageSize); break;

            case "Date": items = items.OrderBy(e => e.DateCreated).Skip((page - 1) * input.PageSize).Take(input.PageSize); break;
            }

            var viewItems = items.ProjectTo <ItemResponseViewModel>();

            this.HttpContext.Cache["data"] = items;

            var viewData = new ItemSearchViewModel()
            {
                CurrentPage = page,
                Items       = viewItems.ToList(),
                TotalPages  = totalPages
            };

            return(View("Index", viewData));
        }
        public ActionResult SearchByWord()
        {
            string word = Request.QueryString["Search"];

            var items = itemRepository.All().Where(i => i.Title.Contains(word) || i.Description.Contains(word));

            this.HttpContext.Cache["data"] = items;

            var viewItems = items.ProjectTo <ItemResponseViewModel>();

            var viewData = new ItemSearchViewModel()
            {
                CurrentPage = 1,
                Items       = viewItems.ToList(),
                TotalPages  = Math.Ceiling((decimal)viewItems.Count() / 5),
                PageSize    = 5
            };

            return(View("Index", viewData));
        }
        public ActionResult ViewPage(int page = 1, int pageSize = 5)
        {
            if (this.HttpContext.Cache["data"] == null)
            {
                return(RedirectToAction("SearchByWord"));
            }

            var count = ((IQueryable <Item>) this.HttpContext.Cache["data"]).Count();

            var items      = ((IQueryable <Item>) this.HttpContext.Cache["data"]).OrderBy(e => e.DateCreated).Skip((page - 1) * pageSize).Take(pageSize);
            var viewItems  = items.ProjectTo <ItemResponseViewModel>();
            var totalPages = Math.Ceiling((decimal)count / pageSize);

            var data = new ItemSearchViewModel()
            {
                CurrentPage = page,
                PageSize    = pageSize,
                Items       = viewItems.ToList(),
                TotalPages  = totalPages
            };

            return(View("Index", data));
        }