コード例 #1
0
ファイル: TasksController.cs プロジェクト: Kokcuk/socialforce
 public TasksController(TaskRepository taskRepository, 
     UserRepository userRepository, OrdersRepository ordersRepository,
     UserResponseHistoryRepository userResponseHistoryRepository, 
     UserService userService,
     BillingService billingService,
     GigbucketDbContext dbContext)
 {
     _taskRepository = taskRepository;
     _userRepository = userRepository;
     _ordersRepository = ordersRepository;
     _userResponseHistoryRepository = userResponseHistoryRepository;
     _userService = userService;
     _billingService = billingService;
     _dbContext = dbContext;
 }
コード例 #2
0
        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);
            }
        }