public async Task <CartContentResponce> Handle(CartContentRequest request, CancellationToken cancellationToken) { var cart = _cartFactory.LoadOrCreateCart(); var allLineItems = cart.GetAllLineItems(); var lineItemCodes = allLineItems.Select(x => x.Code).Distinct(); var variants = _contentLoader.GetItems(_referenceConverter.GetContentLinks(lineItemCodes).Select(x => x.Value), new LoaderOptions { LanguageLoaderOption.FallbackWithMaster() }).OfType <MovieVariant>(); var prices = _customerPriceService.GetPrices(variants.Select(x => x.Code)).ToDictionary(x => x.CatalogKey.CatalogEntryCode, x => x); var discounts = _customerPriceService.GetDiscountPrices(variants.Select(x => x.ContentLink)).ToDictionary(x => x.EntryLink, x => x); var products = variants.Select( x => new { variant = x.ContentLink, product = _contentLoader.GetItems(x.GetParentProducts(), new LoaderOptions { LanguageLoaderOption.FallbackWithMaster() }).OfType <MovieProduct>() }).ToDictionary(x => x.variant, x => x.product.FirstOrDefault()); var lineItems = cart.GetAllLineItems().Select(x => new LineItem() { Code = x.Code, DisplayName = x.DisplayName, Quantity = Convert.ToInt32(x.Quantity), ImageUrl = "",//products[variants.Where(y => y.Code == x.Code).Select(y => y.ContentLink).First()].PosterPath, Price = prices[x.Code].UnitPrice.ToString(), DiscountPrice = discounts[variants.First(y => y.Code == x.Code).ContentLink].DiscountPrices.Last().Price.ToString(), ProductReference = products[variants.Where(y => y.Code == x.Code).Select(y => y.ContentLink).First()].ContentLink }); var total = _orderGroupCalculator.GetOrderGroupTotals(cart); var tax = _orderGroupCalculator.GetTaxTotal(cart); var orderDiscount = _orderGroupCalculator.GetOrderDiscountTotal(cart); var lineItemDiscount = new Money(cart.GetAllLineItems().Sum(x => x.GetEntryDiscount()), cart.Currency); var noDiscount = new Money(allLineItems.Sum(x => prices[x.Code].UnitPrice.Amount * x.Quantity), cart.Currency); var model = new CartContentResponce() { LineItems = lineItems, Total = total.Total.ToString(), ItemsDiscount = lineItemDiscount.ToString(), OrderDiscount = orderDiscount.ToString(), NoDiscount = noDiscount.ToString() }; return(await Task.FromResult(model)); }