Service

QQ 号登记

Target Type Liberal Target

Created 7/18/2024, 7:51:22 PM

Updated 7/18/2024, 7:51:40 PM

Description 参加任何 7th PecJam 赛道的选手均须提供有效的联系方式。使用本服务以登记 QQ 号信息。 You may bind a Discord account on the settings page otherwise.

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;
8
using PhiZoneApi.Dtos.Responses;
9
using PhiZoneApi.Enums;
10

11
var qq = Parameters["QQ 号"];
12
var eventId = new Guid("13b72170-6515-4a2f-b28a-269d3f363a39");
13
const int reviewerCount = 20;
14
await using (var scope = ServiceProvider.CreateAsyncScope())
15
{
16
    var eventTeamRepository = scope.ServiceProvider.GetRequiredService<IEventTeamRepository>();
17

18
    var eventTeams = await eventTeamRepository.GetEventTeamsAsync(predicate: e =>
19
        e.Division.EventId == eventId && e.Participants.Any(f => f.Id == CurrentUser.Id));
20
    if (eventTeams.Count == 0)
21
    {
22
        return new ServiceResponseDto { Type = ServiceResponseType.Error, Message = "请先于任意赛道创建或加入一个队伍!" };
23
    }
24

25
    foreach (var eventTeam in eventTeams)
26
    {
27
        while (eventTeam.Reserved.Count < 14 + reviewerCount)
28
        {
29
            eventTeam.Reserved.Add(string.Empty);
30
        }
31

32
        var content = eventTeam.Reserved[4] ?? "";
33
        var dict = content.Split('\n')
34
            .Where(e => !string.IsNullOrWhiteSpace(e))
35
            .Select(line => line.Split(":"))
36
            .ToDictionary(parts => int.Parse(parts[0]), parts => parts[1]);
37
        dict[CurrentUser.Id] = $"{CurrentUser.UserName},{qq}";
38
        eventTeam.Reserved[4] = string.Join('\n', dict.Select(pair => $"{pair.Key}:{pair.Value}"));
39
        await eventTeamRepository.UpdateEventTeamAsync(eventTeam);
40
    }
41

42
    return new ServiceResponseDto { Type = ServiceResponseType.Success, Message = "登记成功!" };
43
}