Exemplo n.º 1
0
        public override async Task ExecuteAsync(object parameter)
        {
            try
            {
                if (_importVM.dgCSVPrices.Count != 0)
                {
                    Dictionary <string, int> securityMap = _importService.SecurityMap();
                    Dictionary <string, List <SecurityPriceStore> > securityPrices = new Dictionary <string, List <SecurityPriceStore> >();
                    foreach (PriceImportDataCSV data in _importVM.dgCSVPrices)
                    {
                        if (securityMap.ContainsKey(data.SecuritySymbol))
                        {
                            SecurityPriceStore price = new SecurityPriceStore
                            {
                                ClosePrice  = data.ClosePrice,
                                Date        = data.Date,
                                PriceSource = data.PriceSource,
                                SecurityId  = securityMap[data.SecuritySymbol]
                            };

                            if (!securityPrices.ContainsKey(data.SecuritySymbol))
                            {
                                securityPrices[data.SecuritySymbol] = new List <SecurityPriceStore> {
                                    price
                                };
                            }
                            else
                            {
                                securityPrices[data.SecuritySymbol].Add(price);
                            }
                        }
                    }
                    await _importService.AddImportedPrices(securityPrices);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }