Пример #1
0
        public void Import(ImportParam importParam)
        {
            var validate = new ImportParamValidator().Validate(importParam);

            if (!validate.IsValid)
            {
                throw new ApplicationException($"Falha nos parâmetros de entrada ({string.Join(",", validate.Errors)})");
            }

            var repository = new BovespaRepository();

            var stockNegotiationList = repository.ImportFileHistory(importParam.BasePath, importParam.FileName);

            var stockRepository = new StockRepository();

            var stockDic = new Dictionary <string, Stock>();

            foreach (var stockNegotiation in stockNegotiationList)
            {
                if (!stockDic.ContainsKey(stockNegotiation.Stock.Code))
                {
                    stockDic.Add(stockNegotiation.Stock.Code, stockNegotiation.Stock);
                }
            }

            var stockList = stockDic.Select(a => a.Value).ToList();

            stockRepository.BulkMerge(stockList);

            stockRepository.BulkMerge(stockNegotiationList);
        }