diff --git a/common/ASC.Core.Common/Notify/Telegram/Dao/TelegramDao.cs b/common/ASC.Core.Common/Notify/Telegram/Dao/TelegramDao.cs index 78d3268866..2505a3bf25 100644 --- a/common/ASC.Core.Common/Notify/Telegram/Dao/TelegramDao.cs +++ b/common/ASC.Core.Common/Notify/Telegram/Dao/TelegramDao.cs @@ -37,7 +37,7 @@ public class TelegramDao _dbContextFactory = dbContextFactory; } - public void RegisterUser(Guid userId, int tenantId, long telegramId) + public async Task RegisterUserAsync(Guid userId, int tenantId, long telegramId) { var user = new TelegramUser { @@ -46,43 +46,43 @@ public class TelegramDao TelegramUserId = telegramId }; - using var dbContext = _dbContextFactory.CreateDbContext(); - dbContext.AddOrUpdate(dbContext.Users, user); - dbContext.SaveChanges(); + using var dbContext = await _dbContextFactory.CreateDbContextAsync(); + await dbContext.AddOrUpdateAsync(q => q.Users, user); + await dbContext.SaveChangesAsync(); } - public TelegramUser GetUser(Guid userId, int tenantId) + public async Task GetUserAsync(Guid userId, int tenantId) { - using var dbContext = _dbContextFactory.CreateDbContext(); - return dbContext.Users.Find(tenantId, userId); + using var dbContext = await _dbContextFactory.CreateDbContextAsync(); + return await dbContext.Users.FindAsync(tenantId, userId); } - public List GetUser(long telegramId) + public async List GetUsersAsync(long telegramId) { - using var dbContext = _dbContextFactory.CreateDbContext(); + using var dbContext = await _dbContextFactory.CreateDbContextAsync(); - return dbContext.Users + return await dbContext.Users .AsNoTracking() .Where(r => r.TelegramUserId == telegramId) - .ToList(); + .ToListAsync(); } - public void Delete(Guid userId, int tenantId) + public async Task DeleteAsync(Guid userId, int tenantId) { - using var dbContext = _dbContextFactory.CreateDbContext(); + using var dbContext = await _dbContextFactory.CreateDbContextAsync(); - dbContext.Users + await dbContext.Users .Where(r => r.PortalUserId == userId) .Where(r => r.TenantId == tenantId) - .ExecuteDelete(); + .ExecuteDeleteAsync(); } - public void Delete(long telegramId) + public async void DeleteAsync(long telegramId) { - using var dbContext = _dbContextFactory.CreateDbContext(); + using var dbContext = await _dbContextFactory.CreateDbContextAsync(); - dbContext.Users + await dbContext.Users .Where(r => r.TelegramUserId == telegramId) - .ExecuteDelete(); + .ExecuteDeleteAsync(); } } diff --git a/common/ASC.Core.Common/Notify/Telegram/TelegramHelper.cs b/common/ASC.Core.Common/Notify/Telegram/TelegramHelper.cs index 38b8d6532f..88cbbfdbd9 100644 --- a/common/ASC.Core.Common/Notify/Telegram/TelegramHelper.cs +++ b/common/ASC.Core.Common/Notify/Telegram/TelegramHelper.cs @@ -85,9 +85,9 @@ public class TelegramHelper } } - public RegStatus UserIsConnected(Guid userId, int tenantId) + public async Task UserIsConnectedAsync(Guid userId, int tenantId) { - if (_telegramDao.GetUser(userId, tenantId) != null) + if (await _telegramDao.GetUserAsync(userId, tenantId) != null) { return RegStatus.Registered; } @@ -111,9 +111,9 @@ public class TelegramHelper _telegramServiceClient.DisableClient(tenantId); } - public void Disconnect(Guid userId, int tenantId) + public async Task DisconnectAsync(Guid userId, int tenantId) { - _telegramDao.Delete(userId, tenantId); + await _telegramDao.DeleteAsync(userId, tenantId); } private bool IsAwaitingRegistration(Guid userId, int tenantId) diff --git a/common/services/ASC.TelegramService/Commands/UserCommands.cs b/common/services/ASC.TelegramService/Commands/UserCommands.cs index abc9363d0c..54cc126410 100644 --- a/common/services/ASC.TelegramService/Commands/UserCommands.cs +++ b/common/services/ASC.TelegramService/Commands/UserCommands.cs @@ -68,7 +68,7 @@ public class UserCommands : CommandContext if (tenantId == TenantId) { - _telegramDao.RegisterUser(portalUserId, tenantId, telegramUserId); + await _telegramDao.RegisterUserAsync(portalUserId, tenantId, telegramUserId); await ReplyAsync("Ok!"); diff --git a/common/services/ASC.TelegramService/TelegramHandler.cs b/common/services/ASC.TelegramService/TelegramHandler.cs index 072d5d376c..5b263fb6bd 100644 --- a/common/services/ASC.TelegramService/TelegramHandler.cs +++ b/common/services/ASC.TelegramService/TelegramHandler.cs @@ -69,7 +69,7 @@ public class TelegramHandler try { - var tgUser = telegramDao.GetUser(Guid.Parse(msg.Reciever), msg.TenantId); + var tgUser = await telegramDao.GetUserAsync(Guid.Parse(msg.Reciever), msg.TenantId); if (tgUser == null) { diff --git a/web/ASC.Web.Api/Api/Settings/SettingsController.cs b/web/ASC.Web.Api/Api/Settings/SettingsController.cs index 3f186b3d76..4f271b16ce 100644 --- a/web/ASC.Web.Api/Api/Settings/SettingsController.cs +++ b/web/ASC.Web.Api/Api/Settings/SettingsController.cs @@ -790,17 +790,17 @@ public class SettingsController : BaseSettingsController /// /// 0 - not connected, 1 - connected, 2 - awaiting confirmation [HttpGet("telegramisconnected")] - public object TelegramIsConnected() + public async Task TelegramIsConnectedAsync() { - return (int)_telegramHelper.UserIsConnected(_authContext.CurrentAccount.ID, Tenant.Id); + return (int) await _telegramHelper.UserIsConnectedAsync(_authContext.CurrentAccount.ID, Tenant.Id); } /// /// Unlinks TelegramBot from your account /// [HttpDelete("telegramdisconnect")] - public void TelegramDisconnect() + public async Task TelegramDisconnectAsync() { - _telegramHelper.Disconnect(_authContext.CurrentAccount.ID, Tenant.Id); + await _telegramHelper.DisconnectAsync(_authContext.CurrentAccount.ID, Tenant.Id); } } \ No newline at end of file