Пример #1
0
        public IEnumerable <PriceSearchInfo> Lookup(string searchName)
        {
            // Get all products matching the search name
            IEnumerable <(string ProductName, WebShop.PriceInfo PriceInfoUsd)> infos =
                _productRepository.GetAll()
                .Where(p => p.Name.ToLower().Contains(searchName.ToLower()))
                .Select(p =>
                        (ProductName: p.Name, PriceInfo: _priceInfoRepository.GetById(p.Id))
                        );

            // Convert each enriched info with the USD->DKK converted price
            IEnumerable <PriceSearchInfo> searchInfos = infos.Select(info => new PriceSearchInfo
            {
                ProductName = info.ProductName,
                PriceDkk    = _currentConversionService.Convert(
                    new Financial.CurrencyValue
                {
                    Symbol = Financial.CurrencySymbol.USD,
                    Amount = info.PriceInfoUsd.PriceUsd
                },
                    Financial.CurrencySymbol.DKK
                    ).Amount
            });

            return(searchInfos);
        }
        public IEnumerable <ItemGroup> GetItemGroups()
        {
            IEnumerable <WebShop.Product> products = _repository.GetAll();

            IEnumerable <ItemGroup> query = products
                                            .GroupBy(p => p.Category?.ToString() ?? "Uncategorized")
                                            .Select(g => new ItemGroup
            {
                Name  = g.Key,
                Count = g.Count(),
                Items = g.Select(p => new Item
                {
                    Name     = p.Name,
                    Supplier = p.Manufacturer
                })
            });

            return(query);
        }