protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { if (_dbContext == null) { var scope = _scopeFactory.CreateScope(); _dbContext = scope.ServiceProvider.GetRequiredService <OnlineExaminationSystemContext>(); } var finishedExams = await _dbContext.Exams .Where(exam => !exam.IsFinished).ToListAsync(); foreach (var exam in finishedExams) { // bir şeyler yap! exam.IsFinished = true; } if (_dbContext.ChangeTracker.HasChanges()) { await _dbContext.SaveChangesAsync(); } _logger.LogInformation("Worker Service is running!"); await Task.Delay(1000, stoppingToken); } }
public override async Task StartAsync(CancellationToken cancellationToken) { var scope = _scopeFactory.CreateScope(); _dbContext = scope.ServiceProvider.GetRequiredService <OnlineExaminationSystemContext>(); await base.StartAsync(cancellationToken); }
public UserService(IMapper mapper, OnlineExaminationSystemContext dbContext, IConfiguration configuration) { _dbContext = dbContext; _mapper = mapper; _configuration = configuration; }
public ExamService(OnlineExaminationSystemContext dbContext, IMapper mapper) { _dbContext = dbContext; _mapper = mapper; }