Exemplo n.º 1
0
        public async Task <IActionResult> Index()
        {
            IEnumerable <BasketItemDto> basketItems = null;

            try
            {
                basketItems = await _basketFacade.GetBasket(1);

                /*basketItems = await _basketFacade.GetBasket(customerId);*/
            }
            catch (HttpRequestException)
            {
                _logger.LogWarning("Exception Occured using Basket Facade");
                basketItems = null;
            }

            IEnumerable <BasketItemViewModel> viewModel = basketItems.Select(b => new BasketItemViewModel
            {
                ProductId = b.ProductId,
                Name      = b.ProductName,
                Quantity  = b.Quantity,
                Price     = b.Price
            });

            return(View(viewModel));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index()
        {
            IEnumerable <BasketItemDto> basketItems = null;

            try
            {
                basketItems = await _basketFacade.GetBasket(1);

                /*basketItems = await _basketFacade.GetBasket(customerId);*/
            }
            catch (HttpRequestException)
            {
                _logger.LogWarning("Exception Occured using Basket Facade");
                basketItems = null;
            }

            IEnumerable <OrderedItemViewModel> orderedItems = basketItems.Select(b => new OrderedItemViewModel
            {
                ProductId   = b.ProductId,
                Quantity    = b.Quantity,
                Price       = b.Price,
                ProductName = b.ProductName,
            });

            double totalPrice = 0;

            foreach (OrderedItemViewModel item in orderedItems)
            {
                totalPrice = totalPrice + (item.Price * item.Quantity);
            }
            ;

            OrderViewModel viewModel = new OrderViewModel()
            {
                CustomerId = 1,
                /*CustomerId = customerId,*/
                OrderedItems = orderedItems,
                TotalPrice   = totalPrice,
            };

            return(View(viewModel));
        }