Beispiel #1
0
        public BooksQueueResponse ProcessManyBooksForMongo(IList <Book> message)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("-----------------Start ProcessManyBooksForMongo() ...-----------------");

            var ids = _pcRepository.BulkInsert <Book>(message);

            var predicate = MXPredicateBuilder.True <Book>();

            predicate = predicate.And(p => ids.Contains(p.Id));

            var entities = _pcRepository.GetMany <Book>(predicate, take: ids.Count);

            Console.WriteLine("\n-----------------Processing Complete..-----------------");
            Console.ResetColor();

            return(new BooksQueueResponse {
                Books = entities
            });
        }
        //just mapping to the same SearchDoc objects so that the same view could be reused.
        public IList <BookSearchDocument> Search(string term)
        {
            var results = new List <BookSearchDocument>();

            if (MXFlagSettingHelper.Get <bool>("bUseElasticSearchEngine"))
            {
                results = _bookSearchRepository.Search <BookSearchDocument>(term, take: 30).ToList();
            }
            else
            {
                IList <Book> books;

                if (term == string.Empty)
                {
                    books = _productCatalogMongoRepository.GetMany <Book>(take: 20);
                }
                else
                {
                    books = _productCatalogMongoRepository.GetManyByTextSearch <Book>(term, 20);
                }

                foreach (var book in books)
                {
                    results.Add(new BookSearchDocument
                    {
                        Id     = book.Id,
                        Title  = book.Name,
                        Author = new MXSearchDenormalizedRefrence {
                            DenormalizedId = book.Author.DenormalizedId, DenormalizedName = book.Author.DenormalizedName
                        },
                        Category = new MXSearchDenormalizedRefrence {
                            DenormalizedId = book.Category.DenormalizedId, DenormalizedName = book.Category.DenormalizedName
                        },
                        AvaliableCopies = book.AvaliableCopies,
                    });
                }
            }

            return(results);
        }