예제 #1
0
        public static async Task <PowerBotChat> AddOrUpdateChat(Message message)
        {
            //Check if messagetype is not private
            if (!(message.Chat.Type == ChatType.Supergroup || message.Chat.Type == ChatType.Supergroup))
            {
                return(null);
            }

            var chatFromDb = await GetChat(message.Chat.Id);

            // New Сhat
            if (chatFromDb == null)
            {
                var chat = new PowerBotChat
                {
                    Id       = message.Chat.Id,
                    Title    = message.Chat.Title,
                    ActiveAt = DateTime.UtcNow,
                };

                var chatEntity = await _dbContext.Chats.AddAsync(chat);

                chatFromDb = chatEntity.Entity;

                await LogsManager.CreateLog($"New Chat ({chatFromDb.Title})", LogLevel.Info);
            }
            // Update Сhat
            else
            {
                if (message.Chat.Type == ChatType.Group || message.Chat.Type == ChatType.Supergroup)
                {
                    chatFromDb.Title    = message.Chat.Title;
                    chatFromDb.ActiveAt = DateTime.UtcNow;
                }
                ;
            }

            await _dbContext.SaveChangesAsync();

            return(chatFromDb);
        }
예제 #2
0
 public static async Task UpdateChat(PowerBotChat chat)
 {
     _dbContext.Update(chat);
     await _dbContext.SaveChangesAsync();
 }