public async Task <IActionResult> Index(Guid categoryId)
        {
            var currentBasketId = Request.Cookies.GetCurrentBasketId(settings);

            var getBasket = currentBasketId == Guid.Empty ? Task.FromResult <Basket>(null) :
                            shoppingBasketService.GetBasket(currentBasketId);

            var getCategories = eventCatalogService.GetCategories();

            var getEvents = categoryId == Guid.Empty ? eventCatalogService.GetAll() :
                            eventCatalogService.GetByCategoryId(categoryId);

            await Task.WhenAll(new Task[] { getBasket, getCategories, getEvents });

            var numberOfItems = getBasket.Result?.NumberOfItems ?? 0;

            return(View(
                       new EventListModel
            {
                Events = getEvents.Result,
                Categories = getCategories.Result,
                NumberOfItems = numberOfItems,
                SelectedCategory = categoryId
            }
                       ));
        }
        public async Task <IActionResult> Index()
        {
            // we return 200 ok, when we can access the DB categories and events
            var getCategories = eventCatalogService.GetCategories();
            var getEvents     = eventCatalogService.GetAll();
            await Task.WhenAll(new Task[] { getCategories, getEvents });

            return(Ok());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Index(Guid categoryId)
        {
            var currentBasketId = Request.Cookies.GetCurrentBasketId(_settings);

            var getBasket     = _shoppingBasketService.GetBasket(currentBasketId);
            var getCategories = _eventCatalogService.GetCategories();
            var getEvents     = categoryId == Guid.Empty
                ? _eventCatalogService.GetAll()
                : _eventCatalogService.GetByCategoryId(categoryId);

            await Task.WhenAll(new Task[] { getCategories, getEvents, getBasket });

            return(View(new EventListModel
            {
                Events = getEvents.Result,
                Categories = getCategories.Result,
                SelectedCategory = categoryId,
                NumberOfItems = getBasket.Result is null ? 0 : getBasket.Result.NumberOfItems
            }));