示例#1
0
    public async Task <(bool Success, string Message)> RegisterUser(uint lbId, SocketGuildUser user)
    {
        try
        {
            uint[] playerRequest = { lbId };

            EntryResponse lbPlayer  = (await _webService.GetLbPlayers(playerRequest))[0];
            DdUser        newDdUser = new(user.Id, lbPlayer.Id);
            using IServiceScope scope       = _scopeFactory.CreateScope();
            await using DbService dbContext = scope.ServiceProvider.GetRequiredService <DbService>();
            await dbContext.AddAsync(newDdUser);

            await dbContext.SaveChangesAsync();

            return(true, string.Empty);
        }
        catch (Exception ex)
        {
            return(ex switch
            {
                CustomException => (false, ex.Message),
                HttpRequestException => (false, "DD servers are most likely down."),
                IOException => (false, "IO error."),
                _ => (false, "No reason specified."),
            });