IEnumerable <Product> ICurrencyConverterService.ConvertTo(IEnumerable <Product> productList, Currency toCurrency) { var convertedList = new List <Product>(); foreach (var price in productList) { ICurrencyConverterService srv = this; var newProduct = price.Clone() as Product; if (newProduct != null && newProduct.Price != null) { newProduct.Price = srv.ConvertTo(newProduct.Price, toCurrency); } convertedList.Add(newProduct); } return(convertedList); }
async Task ICommandAsync.Execute() { var banner = FiggleFonts.Big.Render("Challenge - 1"); Console.WriteLine(banner); const string CSVFILEURI = "https://henrybeen.nl/wp-content/uploads/2020/10/001-experts-inputs.csv"; var productList = await _csvService.DownloadCsv(new Uri(CSVFILEURI)).ConfigureAwait(false); var filteredProductList = productList.Where(product => !(product.Price.Value < 10)); var convertedProductList = _currencyService.ConvertTo(filteredProductList, Currency.EUR); const string CSVFILENAME = "ProductListInEuros.csv"; string path = $@"{Directory.GetCurrentDirectory()}/{CSVFILENAME}"; using var textWriter = new StreamWriter(path); _csvService.SaveCsv(convertedProductList, textWriter); string closingNotification = $"Opening csv with {convertedProductList.Count()} rows in Notepad..."; Process.Start("notepad.exe", path); }