public async Task <IActionResult> Search([FromQuery] SearchOptionsModel searchOptions)
        {
            searchOptions.PageNumber = Math.Max(searchOptions.PageNumber, 1);

            const int takeCount = 10;

            var result = await this.transactionRepository.SearchTransaction(
                new TransactionSearchOptions
            {
                CurrencyCode = searchOptions.Currency,
                Status       = searchOptions.Status,
                FromDate     = searchOptions.FromDate,
                ToDate       = searchOptions.ToDate,
                Skip         = (searchOptions.PageNumber - 1) * takeCount,
                Take         = takeCount,
            });

            return(this.View(new SearchViewModel
            {
                SearchOptions = searchOptions,
                Transactions = result.Items.Select(x =>
                                                   new TransactionModel
                {
                    Id = x.Id,
                    Payment = $"{x.Amount:0.00} {x.CurrencyCode}",
                    Status = x.Status.ToString().Substring(0, 1),
                })
                               .ToArray(),
                Pagination = new Pagination((page) => $"filter({page})", result.Count, searchOptions.PageNumber, takeCount),
            }));
        }
Пример #2
0
        public async Task <ActionResult> Search(SearchOptionsModel opt)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index"));
            }

            var model = await DoSearch(SearchMode.Keywords, opt);

            return(View("Index", model));
        }
Пример #3
0
        public static List <Item> ItemSearch(SearchOptionsModel model)
        {
            string str = model.Query ?? "";
            // Flag to see if none of the search options ticked, default to search for Item name.
            bool flag = false;

            // List of items to display on result page
            List <Item> itemsToDisplay = new List <Item>();

            if (!str.Equals(""))
            {
                // All items is queried first to minimize request to database
                var allItems = db.Items.ToList();

                string[] splited = str.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var s in splited)
                {
                    if (model.InclName == true)
                    {
                        flag           = true;
                        itemsToDisplay = itemsToDisplay.Union(allItems.Where(row => row.Name.ToLower().Contains(s.ToLower()))).ToList();
                    }
                    if (model.InclDescription == true)
                    {
                        flag           = true;
                        itemsToDisplay = itemsToDisplay.Union(allItems.Where(row => row.Description.ToLower().Contains(s.ToLower()))).ToList();
                    }
                    if (model.InclTrade == true)
                    {
                        flag           = true;
                        itemsToDisplay = itemsToDisplay.Union(allItems.Where(row => (row.Trade != null) ? row.Trade.ToLower().Contains(s.ToLower()) : false)).ToList();
                    }
                    if (model.InclUser == true)
                    {
                        flag           = true;
                        itemsToDisplay = itemsToDisplay.Union(allItems.Where(row => row.UserProfile.UserName.ToLower().Contains(s.ToLower()))).ToList();
                    }
                    if (model.TypeId != 0)
                    {
                        itemsToDisplay = itemsToDisplay.Where(row => row.TypeId == model.TypeId).ToList();
                    }
                    if (flag == false)
                    {
                        flag           = true;
                        model.InclName = true;
                        itemsToDisplay = itemsToDisplay.Union(allItems.Where(row => row.Name.ToLower().Contains(s.ToLower()))).ToList();
                    }
                }
            }
            return(itemsToDisplay);
        }
Пример #4
0
        private async Task <SearchViewModel> DoSearch(SearchMode mode, SearchOptionsModel opt)
        {
            IStorage s = _storageFactory.ResolveStorage();

            var searchOptions = Mapper.Map <SearchOptions>(opt);

            searchOptions.PageSize = _settings.PageSize;
            searchOptions.Mode     = mode;

            var model = new SearchViewModel
            {
                SearchOptions = searchOptions,
                SearchResults = await s.SearchAsync(searchOptions)
            };

            return(model);
        }
Пример #5
0
        public async Task SetSearchSetting(string userId, SearchOptionsModel obj)
        {
            var setting = await context.SearchOptions
                          .FirstOrDefaultAsync(x => x.UserId == userId && x.Key == obj.Key && x.Type == obj.Type);

            if (setting != null)
            {
                setting.Value = obj.Value;
            }
            else
            {
                var model = Mapper.Map <SearchOption>(obj);
                model.UserId = userId;
                context.SearchOptions.Add(model);
            }

            await context.SaveChangesAsync();
        }
Пример #6
0
        public List <SerializableItem> SearchItems(string Query, bool InclName, bool InclDescription, bool InclUser, bool InclTrade, int TypeId)
        {
            SearchOptionsModel model = new SearchOptionsModel()
            {
                Query           = Query,
                InclName        = InclName,
                InclDescription = InclDescription,
                InclUser        = InclUser,
                InclTrade       = InclTrade,
                TypeId          = TypeId
            };
            List <SerializableItem> serializableItems = new List <SerializableItem>();

            foreach (var item in ItemsManagement.ItemSearch(model))
            {
                serializableItems.Add(new SerializableItem(item));
            }
            return(serializableItems);
        }
Пример #7
0
        //
        // Search result
        // GET: /Search/s={parameter}
        public ActionResult Index(int?page, SearchOptionsModel model)
        {
            ViewBag.Result = "Search results";
            int pageNumber = page ?? 1;
            var vm         = new SearchResultModel();

            if (model.TypeList == null)
            {
                model.TypeList = new SelectList(db.Types, "TypeId", "Name");
            }
            var itemsToDisplay = ItemsManagement.ItemSearch(model).ToPagedList(pageNumber, 9);

            if (itemsToDisplay.Count == 0)
            {
                ViewBag.Result = "No result found.";
            }

            vm.Items          = itemsToDisplay;
            vm.CurrentOptions = model;
            return(this.View(vm));
        }
Пример #8
0
 public async Task SetSearchSetting(SearchOptionsModel obj) =>
 await _setupService.SetSearchSetting(User.Identity.GetUserId(), obj);