public async Task <IActionResult> RefreshAnnualFinancialStatements()
        {
            var isAuthorized = await _authorizationService.AuthorizeAsync(User, new Stock(), StockOperations.Refresh);

            if (!isAuthorized.Succeeded)
            {
                return(new ChallengeResult());
            }
            var stocks = _context.Stocks
                         .Include(s => s.FinancialStatements)
                         .ThenInclude(f => f.BalanceSheet)
                         .Include(s => s.FinancialStatements)
                         .ThenInclude(f => f.IncomeStatement)
                         .Include(s => s.FinancialStatements)
                         .ThenInclude(f => f.CashFlowStatement).OrderBy(s => s.Ticker);

            try
            {
                await _financialStatementUpdater.UpdateFinancialStatementsBatchAsync(stocks, StatementFrequency.Annual);

                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(Content("Failure : " + e.Message + ((e.InnerException != null) ? e.InnerException.Message : String.Empty)));
            }
            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 2
0
        public async Task RetrieveAllFinancialStatements(int whichBatch, int batchSize, int minId, int maxId, StatementFrequency frequency)
        {
            var idFrom = minId + (whichBatch - 1) * batchSize;
            var idTo   = minId + (whichBatch * batchSize) - 1;
            var stocks = _context.Stocks
                         .Include(s => s.FinancialStatements)
                         .ThenInclude(f => f.BalanceSheet)
                         .Include(s => s.FinancialStatements)
                         .ThenInclude(f => f.IncomeStatement)
                         .Include(s => s.FinancialStatements)
                         .ThenInclude(f => f.CashFlowStatement).
                         Where(x => x.Id >= idFrom && x.Id <= idTo);
            await _financialStatementUpdater.UpdateFinancialStatementsBatchAsync(stocks, frequency);

            await _context.SaveChangesAsync();
        }