Esempio n. 1
0
        public IEnumerable <BookDto> Get()
        {
            var savedIds = savedItemsProvider.Get();

            return(context.Get <IEnumerable <BookDto> >(Key)
                   .NullSafe()
                   .Select(x =>
            {
                x.IsSaved = savedIds.Any(id => id == x.Id);
                return x;
            }));
        }
        public IViewComponentResult Invoke()
        {
            var savedItems = savedItemsProvider.Get();
            var books      = provider.Get();
            var cart       = cartProvider.Get();
            var vm         = new BookListViewData
            {
                CategoryName = categoryMenuProvider.Get().FirstOrDefault(x => x.Name.ToSlug() == currentCategoryProvider.Get())?.Name,
                Books        = books.Select(x =>
                {
                    x.IsSaved          = savedItems.Any(i => i == x.Id);
                    x.TotalItemsInCart = cart.Items?.FirstOrDefault(item => item.BookId == x.Id)?.Quantity ?? 0;
                    return(x);
                }).ToArray()
            };

            return(View("~/Features/Search/List/Views/BooksList.cshtml", vm));
        }
        public async Task <IActionResult> Index(DetailsQuery query)
        {
            logger.Trace("Start requesting details page...");

            var taskGetDetails = bus.SendAsync <DetailsQuery, DetailsViewModel>(query);

            await Task.WhenAll(taskGetDetails, bus.PublishAsync(new DetailsPageRequestedEvent()));

            var response = taskGetDetails.Result;

            if (response.Value == null)
            {
                return(Redirect("~/"));
            }

            response.Value.IsSaved = savedItemsProvider.Get().Any(x => x == response.Value.Id);

            return(View(response.Value));
        }