mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
initial chat options implementation
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using System.Threading.Tasks;
|
||||
using Kruzya.TelegramBot.Core.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.Extensions;
|
||||
|
||||
public partial class RepositoryExtension
|
||||
{
|
||||
public static async Task<ChatOptionValue> FindOption(this DbSet<ChatOptionValue> repository, long chatId,
|
||||
string optionId)
|
||||
{
|
||||
return await repository.SingleOrDefaultAsync(x => x.ChatId == chatId && x.OptionId == optionId);
|
||||
}
|
||||
|
||||
public static async Task<ChatOptionValue> FindOrCreateOption(this DbSet<ChatOptionValue> repository, long chatId,
|
||||
string optionId)
|
||||
{
|
||||
var opt = await repository.FindOption(chatId, optionId) ?? new ChatOptionValue
|
||||
{
|
||||
ChatId = chatId,
|
||||
OptionId = optionId
|
||||
};
|
||||
|
||||
return opt;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user