public void Execute(IJobExecutionContext context) { try { Console.WriteLine("AutoApproveTaskJob"); var dbContext = new GigbucketDbContext(); var userResponseHistoryRepository = new UserResponseHistoryRepository(dbContext); var userService = new UserService(new UserRepository(dbContext), new ReviewRepository(dbContext), userResponseHistoryRepository); var billingService = new BillingService(dbContext); var expiredTasks = dbContext.Task .Include(x => x.Order) .Include(x => x.Order.User) .Include(x => x.User) .Where(x => x.IsDeleted == false && x.TaskStatus == TaskStatus.InReview && DbFunctions.DiffDays(x.CreateDate, DateTime.Now) > 3).ToList(); foreach (var task in expiredTasks) { _logger.Debug("task id:{0} order owner:{1} {2} task owner:{3} {4}", task.Id, task.Order.User.Id, task.Order.User.FullName, task.User.Id, task.User.FullName); var orderOwenerUser = task.Order.User; task.TaskStatus = TaskStatus.Completed; task.Order.TasksInReview--; userService.RebuildUserRating(task.User.Id); var responseDelta = (DateTime.Now - task.CreateDate).TotalMinutes; var userResponse = new UserResponseHistory { User = orderOwenerUser, CreateDate = DateTime.Now, ResponseMins = responseDelta }; userResponseHistoryRepository.Save(userResponse); userService.RebuildResponseTime(orderOwenerUser.Id); billingService.Transfer(orderOwenerUser, task.User, task.Order.Price); _logger.Debug("Force change status"); } dbContext.SaveChanges(); } catch (Exception ex) { _logger.Error(ex); } }
public void Save(UserResponseHistory userResponseHistory) { _dbContext.UserResponseHistory.Add(userResponseHistory); _dbContext.SaveChanges(); }