using System;
using BotFramework;
using Microsoft.EntityFrameworkCore;
namespace Kruzya.TelegramBot.Core;
///
/// Resolves the GUIDs from database to entities.
///
/// Entity type
/// Database context where entity should be finded
public class DbResolverParameter : IParameterParser
where TAppContext : DbContext
where TResolvedEntity : class
{
private TAppContext _dbContext;
public DbResolverParameter(TAppContext dbContext)
{
_dbContext = dbContext;
}
public TResolvedEntity DefaultInstance()
{
return default(TResolvedEntity);
}
public bool TryGetValue(string text, out TResolvedEntity result)
{
result = null;
Guid id;
if (Guid.TryParse(text, out id))
{
result = _dbContext.Find(id);
return (result != null);
}
return false;
}
}