MyDBContext db = new MyDBContext();
using var db = new MyDBContext();
private async Task BotOnMessageReceived(Message message)
{
_logger.LogInformation("Receive message type: {MessageType}", message.Type);
if (message.Type != MessageType.Text)
await _botClient.SendTextMessageAsync(message.Chat.Id, "Send only text commands!");
var action = message.Text!.Split(' ')[0] switch
{
"/start" => StartMessageService.StartCommand(_botClient, message),
"/help" => HelpMessageService.HelpCommand(_botClient, message),
"/add" => AddAccountService.AddCommand(_botClient, message),
"/parse" => ParseCommandService.ParseCommand(_botClient, message),
"/show" => ShowCommandService.ShowCommand(_botClient, message),
_ => BackToMainMenuService.BackToMainMenu(_botClient, message)
};
Message sentMessage = await action;
_logger.LogInformation("The message was sent with id: {SentMessageId}", sentMessage.MessageId);
}public class StartMessageService
{
public static async Task<Message> StartCommand(ITelegramBotClient bot, Message message)
{
return await bot.SendTextMessageAsync(message.Chat.Id, "Welcome txt here");
}
}public class AddAccountService
{
public static async Task<Message> AddCommand(ITelegramBotClient bot, Message message)
{
if(message.Text.Count(char.IsWhiteSpace) == 1)
{
string[] getData = message.Text.Split(" ");
var user = new UserInformation
{
TelegramUserId = message.Chat.Id.ToString()
};
user.Accounts.Add(new Account
{
SteamId = getData[1]
});
return await bot.SendTextMessageAsync(message.Chat.Id, "Saved");
}
return await bot.SendTextMessageAsync(message.Chat.Id, "Wrong command. Please, keep order of the commands.");
}
}public static async Task<Message> AddCommand(ITelegramBotClient bot, Message message, dbContext context) запись в таблице бд не появляется. Помогите, пожалуйста.