public async Task <IActionResult> Get(string userId)
        {
            await Task.Delay(130);

            if (items != null)
            {
                return(Ok(items));
            }

            lock (_lock)
            {
                if (items != null)
                {
                    return(Ok(items));
                }


                var rnd = new Random();

                items = BookData.GetAll()
                        .Select(x => new { Book = x, Rnd = rnd.Next(1, 100) })
                        .OrderBy(x => x.Rnd)
                        .Take(rnd.Next(3, 7))
                        .Select(
                    x => new CartItemDto
                {
                    Quantity = rnd.Next(1, 4),
                    Price    = x.Book.Price,
                    BookId   = x.Book.Id,
                    Title    = x.Book.Title
                }).ToList();
            }

            return(Ok(items));
        }
        public async Task <IActionResult> Get(string userId)
        {
            await Task.Delay(170);

            var rnd = new Random();

            return(Ok(BookData.GetAll().Select(x => new { Book = x, Rnd = rnd.Next(1, 100) }).OrderBy(x => x.Rnd).Take(4).Select(x => x.Book)));
        }
Пример #3
0
        public async Task <IActionResult> Get(string category)
        {
            await Task.Delay(180);

            return
                (Ok(BookData.GetAll()
                    .Where(x => string.Equals(x.UrlFriendlyCategory, category, StringComparison.OrdinalIgnoreCase))
                    .OrderBy(x => x.Title)));
        }
    public async Task <IActionResult> Get()
    {
        await Task.Delay(150);

        return(Ok(BookData.GetAll().GroupBy(l => l.Category)
                  .Select(g => new
                          CategoryDto {
            Name = g.Key,
            Count = g.Select(l => l.Id).Distinct().Count()
        }).OrderBy(x => x.Name)));
    }
        public async Task <IActionResult> Get(string id)
        {
            await Task.Delay(100);

            var book = BookData.GetAll().FirstOrDefault(x => x.Id == id);

            if (book == null)
            {
                return(NotFound());
            }

            return(Ok(book));
        }
Пример #6
0
        public async Task <IActionResult> Latest()
        {
            await Task.Delay(160);

            return(Ok(BookData.GetAll().OrderByDescending(x => x.CreatedAtUtc).Take(4)));

            var result = new List <BookListItemDto>
            {
                new BookListItemDto
                {
                    Id     = "24817626",
                    Title  = "Go Set a Watchman",
                    Image  = "https://d.gr-assets.com/books/1451442088l/24817626.jpg",
                    Price  = 23.56m,
                    Author = "Harper Lee"
                }, new BookListItemDto
                {
                    Id     = "24941288",
                    Title  = "After You",
                    Image  = "https://d.gr-assets.com/books/1425496284l/24941288.jpg",
                    Price  = 39.50m,
                    Author = "Jojo Moyes"
                }, new BookListItemDto
                {
                    Id     = "22875451",
                    Title  = "The Royal We",
                    Image  = "https://d.gr-assets.com/books/1421107274l/22875451.jpg",
                    Price  = 25.99m,
                    Author = "Heather Cocks"
                }, new BookListItemDto
                {
                    Id     = "22822858",
                    Title  = "A Little Life",
                    Image  = "https://d.gr-assets.com/books/1446469353l/22822858.jpg",
                    Price  = 23.56m,
                    Author = "Hanya Yanagihara"
                }
            };


            return(Ok(result));
        }
        public async Task <IActionResult> Featured()
        {
            await Task.Delay(100);

            return(Ok(BookData.GetAll().OrderByDescending(x => x.Popularity).Take(4)));

            var result = new List <BookListItemDto>
            {
                new BookListItemDto
                {
                    Id     = "22522808",
                    Title  = "Trigger Warning",
                    Image  = "https://d.gr-assets.com/books/1415036119l/22522808.jpg",
                    Price  = 23.56m,
                    Author = "Neil Gaiman"
                }, new BookListItemDto
                {
                    Id     = "22055262",
                    Title  = "A Darker Shade of Magic",
                    Image  = "https://d.gr-assets.com/books/1400322851l/22055262.jpg",
                    Price  = 39.50m,
                    Author = "V.E. Schwab"
                }, new BookListItemDto
                {
                    Id     = "16065004",
                    Title  = "Shadows of Self",
                    Image  = "https://d.gr-assets.com/books/1435053013l/16065004.jpg",
                    Price  = 25.99m,
                    Author = "Brandon Sanderson"
                }, new BookListItemDto
                {
                    Id     = "17333171",
                    Title  = "Magic Shifts",
                    Image  = "https://d.gr-assets.com/books/1414091260l/17333171.jpg",
                    Price  = 23.56m,
                    Author = "Ilona Andrews"
                }
            };


            return(Ok(result));
        }
Пример #8
0
        public IActionResult Index()
        {
            ViewBag.books = BookData.GetAll();

            return(View());
        }