Beispiel #1
0
 public virtual void PlaceAnOrder(BookKey[] booksIAmBuying)
 {
     foreach (var bookToBuy in booksIAmBuying)
     {
         SoldBooks.Add(new SoldBook {SoldBookKey = bookToBuy});
     }
 }
 public List<Book> GetDetailsAboutBooks(BookKey[] books)
 {
     using (var session = _database.OpenSession())
     {
         return _mapper.Map<List<Book>>(session.Query<RmBook>().Where(book => book.Key.In(books)));
     }
 }
Beispiel #3
0
 public IEnumerable<RmAvailableBook> GetBooksAvailableForSale(BookKey[] books)
 {
     using (IDbConnection connection = new SqlConnection(_connectionStrings.SalesDb))
     {
         return connection.Query<RmAvailableBook>(@"SELECT * FROM Book WHERE BookKey In @keys", new {keys = books.Select(b => b.Value).ToArray()});
     }
 }
Beispiel #4
0
 public void AddToCart(BookKey book)
 {
     if (!Items.ContainsKey(book.Value))
         Items.Add(book.Value, new BookOrder(book));
     else
     {
         Items[book.Value].Quantity++;
     }
 }
        public List<SoldBook> FindBooksWhoPeopleAlsoBoughtWhenTheyBought(BookKey book)
        {
            var query = new CypherQuery(@"start n=node(*) where has(n.Id) and n.Id = {p0} return n", new Dictionary<string, object> {{"p0", book.Value}}, CypherResultMode.Set);

            var books = ((IRawGraphClient) _client).ExecuteGetCypherResults<Node<Book>>(query).ToList();

            IEnumerable<Node<Book>> soldBooks = _client.Cypher.Start(new {n = books}).Match("(n)--(x)").Return<Node<Book>>("x").Results;

            return soldBooks.Select(bookReference => new SoldBook{ Id = new BookKey{ Value = bookReference.Data.Id }}).ToList();
        }
        public IEnumerable<BookViewModel> Get(int bookId)
        {
            var selectedBookKey = new BookKey { Value = bookId };
            var alsoBought = _marketingInfoProvider.Execute(service => service.FindBooksWhoPeopleAlsoBoughtWhenTheyBought(selectedBookKey)).Select(b => b.Id).ToList();

            var bookDetails = _bookDetailsProvider.Execute(service => service.GetDetailsAboutBooks(alsoBought.ToArray()));
            var prices = _priceProvider.Execute(service => service.GetBooksAvailableForSale(alsoBought.ToArray()));

            var alsoPurchased = bookDetails.Select(details => new BookViewModel
            {
                Author = details.Author,
                Category = details.Category,
                Id = details.Id,
                PriceInOere = prices.First(price => price.Id == details.Id).Price.PriceInOere,
                Published = details.Published,
                Title = details.Title,
                CoverFilename = details.CoverFilename
            }).ToList();
            return alsoPurchased;
        }
Beispiel #7
0
 public BookOrder(BookKey book)
 {
     Book = book;
     Quantity = 1;
 }
Beispiel #8
0
        public List<AvailableBook> GetBooksAvailableForSale(BookKey[] books)
        {
            var result = _queries.GetBooksAvailableForSale(books);

            return _mapper.Map<List<AvailableBook>>(result);
        }