Beispiel #1
0
        public int CheckoutBooks(IEnumerable <int> ids)
        {
            var books = GetBooksFromDb.Where(b => ids.Any(i => i == b.Id));

            if (books.Any(b => b.Quantity == 0))
            {
                throw new ChangeConflictException();
            }

            foreach (var book in books)
            {
                book.Quantity   = --book.Quantity;
                book.Popularity = ++book.Popularity;
            }

            var order = new Order
            {
                Books       = books.ToList(),
                Credentials = HttpContext.Current.User.Identity.GetUserName(),
                Time        = DateTime.UtcNow
            };

            order = _db.Orders.Add(order);
            _db.SaveChanges();
            return(order.Id);
        }
Beispiel #2
0
 public IEnumerable <Book> SearchBooks(string query) => GetBooksFromDb
 .Where(b => b.FullTitle.Contains(query))
 .OrderBy(b => b.Popularity)
 .ThenBy(b => b.Title)
 .ToList();
Beispiel #3
0
 public IEnumerable <Book> GetBooksByGenre(int id) => GetBooksFromDb
 .Where(b => b.Genres.Any(g => g.Id == id))
 .OrderBy(b => b.Popularity)
 .ThenBy(b => b.Title)
 .ToList();