mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
26 lines
796 B
C#
26 lines
796 B
C#
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;
|
|
}
|
|
} |