Esempio n. 1
0
        public PaymentController(AppDbContext context,
                                 ILogger <CompanyUser> logger, ICompanyUserRepository companyuser_repo,
                                 IUserFinRepository fin,
                                 SharedViewLocalizer localizer)
        {
            _context = context;

            _logger = logger;

            _fin       = fin;
            _localizer = localizer;
        }
Esempio n. 2
0
        public string Schedule => "0 23 * * *";  //every day  at 23:00
#endif
        public async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Start job to Write Off production day");
            IsRunning = true;
            try
            {
                using (var serviceScope = _serviceProvider.CreateScope())
                {
                    AppDbContext context = serviceScope.ServiceProvider.GetRequiredService <AppDbContext>();
                    if (context == null)
                    {
                        _logger.LogError("Can't  obtain DB context");
                        return;
                    }

                    foreach (var cmp in await context.Companies.AsNoTracking().ToListAsync())
                    {
                        IUserFinRepository finrepo = serviceScope.ServiceProvider.GetRequiredService <IUserFinRepository>();
                        if (finrepo == null)
                        {
                            _logger.LogError("Can't  obtain fin repository object");
                            return;
                        }
                        await finrepo.MakeOrderPaymentAsync(DateTime.Now, cmp.Id);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Write of production error");
            }
            finally
            {
                IsRunning = false;
            }
        }