Automated Task

公示作品 Day 3

Type Scheduled

Date Executed 8/20/2024, 2:00:00 AM

Created 8/18/2024, 6:36:20 AM

Updated 8/18/2024, 6:38:45 AM

Code
1
using Microsoft.Extensions.Logging;
2
using Microsoft.Extensions.DependencyInjection;
3
using PhiZoneApi.Models;
4
using PhiZoneApi.Interfaces;
5
using System.Collections.Generic;
6
using System.Linq;
7
using System.IO;
8
using System;
9
using System.Globalization;
10
using System.Text;
11

12
var t = (EventDivision)Target;
13
var dateLimit = DateTimeOffset.Parse("2024-08-12T18:00:00+00:00");
14
await using (var scope = ServiceProvider.CreateAsyncScope())
15
{
16
    var chartRepository = scope.ServiceProvider.GetRequiredService<IChartRepository>();
17
    var eventResourceRepository = scope.ServiceProvider.GetRequiredService<IEventResourceRepository>();
18

19
    var entries =
20
        (await eventResourceRepository.GetEventResourcesAsync(predicate: e => e.DivisionId == t.Id)).Select(e =>
21
            e.ResourceId);
22
    var charts = await chartRepository.GetChartsAsync(predicate: e =>
23
        entries.Contains(e.Id) && e.DateUpdated < dateLimit, showAnonymous: true);
24
    foreach (var chart in charts)
25
    {
26
        chart.IsHidden = false;
27
    }
28

29
    await chartRepository.UpdateChartsAsync(charts);
30
}